Getting data from reference table using FK - MJoin
Getting data from reference table using FK - MJoin
patrick008
Posts: 4Questions: 2Answers: 0
I am trying to get the Name field from TlkUserRoleType' table which is being referenced in 'UserRole' table using 'MJoin'.
UserRole & TlkUserRolesType tables are linked using FK RoleID in UserRole table.
Here's my Json response code:
var response = new Editor(db, "UserRole")
.Model<UserRoleModel>()
.Field(new Field("UserRole.ID"))
.Field(new Field("UserRole.UserID"))
.Field(new Field("UserRole.RoleID"))
.Field(new Field("UserRole.SupervisorUserID"))
.Field(new Field("UserRole.ApprovedByUserID"))
.Field(new Field("UserRole.ActivatedDate"))
.Field(new Field("UserRole.IsActive"))
.Field(new Field("UserRole.DeactivatedDate"))
.MJoin(new MJoin("TlkUserRolesType")
.Link("UserRole.RoleID", "TlkUserRolesType.ID")
.Field(new Field("TlkUserRolesType.Name"))
)
.Process(request)
.Data();
When the table is rendered, it does not give me the 'Name' value from TlkUserRolesType. I noticed that in Json Response, the last field is coming as a collection of objects like below:
[0]: {[DT_RowId, row_1]}
[1]: {[UserRole, System.Collections.Generic.Dictionary`2[System.String,System.Object]]}
[2]: {[id, 1]}
[3]: {[userid, 1]}
[4]: {[roleid, 1]}
[5]: {[supervisoruserid, 2]}
[6]: {[approvedbyuserid, 3]}
[7]: {[activateddate, 6/2/2017 12:00:00 AM]}
[8]: {[isactive, True]}
[9]: {[deactivateddate, ]}
[10]: {[TlkUserRolesType, System.Collections.Generic.List`1[System.Object]]}
Is there anything I should be changing in my code?
Thank you!
This discussion has been closed.
Answers
that is what Mjoin does: it returns an array of objects. You seem to only want a normal left join. This example has both: an mjoin to show / select an array of permissions and a left join to show / select exactly one site.
https://editor.datatables.net/examples/advanced/joinArray.html
Thank you, rf1234! I implemented the change and got one step closer.
Now, I see the Role Name in the 'Edit' window but the RoleName column is still blank in the grid itself. (Screenshots attached)
My method in controller is this:
And my javascript code for table is:
} );
To me all looks fine. Did you check the database whether the update of the field was really made?