I'm having a Problem with MJoin
I'm having a Problem with MJoin
I started to look at the MJoin functionality today (following this example: https://editor.datatables.net/manual/net/mjoin) and ran into a problem. Here's my code:
.MJoin(new MJoin("Finish")
.Link("Product.Id", "ProductFinish.ProductId")
.Link("Finish.Id", "ProductFinish.FinishId")
.Model<JoinFinishModel>()
.Field(new Field("Id")
.Options("Finish", "Id", "Name"))
)
The error I get back is:
{"draw":null,"data":[],"recordsTotal":null,"recordsFiltered":null,"error":"Join was performed on the field 'Product.Id' which was not included in the Editor field list. The join field must be included as a regular field in the Editor instance.","fieldErrors":[],"id":null,"meta":{},"options":{},"files":{},"upload":{"id":null}}
I have tried adding in "Product.Id" as member of my ProductModel but that didn't do the trick either
.Field(new Field("Product.Id"))
It might be worth noting that "Product.Id" is a GUID field (not sure if that makes a difference)
Any help will be greatly appreciated.
This question has an accepted answers - jump to answer
Answers
Hi,
Is
Id
the primary key of theProduct
table? If so, when you create the Editor instance, pass that in as the third parameter:Allan
Hi Allan,
Thanks for that, that has resolved the issue, however I now have a new error:
{"draw":null,"data":[],"recordsTotal":null,"recordsFiltered":null,"error":"Type error - Data set for Product.Id is not of type String.","fieldErrors":[],"id":null,"meta":{},"options":{},"files":{},"upload":{"id":null}}
Any ideas?
Cheers,
Nathan
Hi Allan, I seemed to have resolved the issue by removing the following which I left in there.
.Field(new Field("Product.Id"))
Thank you so much for your assistance.
Hi Allan, Really sorry I'm still not quite there yet..
My json results don't appear to have any of the mJoin information (See below). I would have expected to see it even if there is no data in the table right?
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
Hi Allan,
Just to check, I put some values in the linked table (ProductFinish) manually and then field appeared (see below).
Should that be the case that there must be a record in the linked table for it to work?
Just thought I'd make you aware of it.
Thanks once again for your help.
Nathan
Hi Nathan,
This is expected - if there is no join information then Editor simply won't both adding it to the JSON data (I'm slightly surprised that it adds an empty array actually).
columns.defaultContent
can be used to tell DataTables what to do with a field which doesn't exist.Regards,
Allan
Hi Allan,
I'm actually pleased it adds an empty array. Without this the checkboxes are not there by default.
I wouldn't think this would be expected. I.e. how can a user enter data without the checkboxes existing?
I have noticed another issue in relation to the this functionality, in that they do not insert a new record when we create an item. The checkboxes only work on 'update'.
Cheers,
Nathan