I'm having a Problem with MJoin

I'm having a Problem with MJoin

sudderssudders Posts: 8Questions: 2Answers: 0
edited December 2015 in Editor

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

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Hi,

    Is Id the primary key of the Product table? If so, when you create the Editor instance, pass that in as the third parameter:

    new Editor( db, "Product", "Id" )
    

    Allan

  • sudderssudders Posts: 8Questions: 2Answers: 0

    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

  • sudderssudders Posts: 8Questions: 2Answers: 0

    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.

  • sudderssudders Posts: 8Questions: 2Answers: 0
    edited December 2015

    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?

    {
        "draw": null,
        "data": [{
                    "DT_RowId": "row_a60de9a1-fd91-e511-beba-00c2c60bffc1",
                    "Product": {
                        "ProductTypeId": "9",
                        "ColourGroupId": "11",
                        "StyleId": "3",
                        "JoinTypeId": "1",
                        "BusinessUnitId": null,
                        "ImageId": 1,
                        "DefaultDisplayCode": "1403",
                        "RenderCode": "1403",
                        "DefaultDisplayName": "White Pearl Wood",
                        "Width": 1219,
                        "Depth": 2438,
                        "HasBlackEdge": false,
                        "TextureFile": "1403 WHITE PEARL WOOD.jpg",
                        "IsActive": false
                    },
                    "ProductType": {
                        "Name": "Laminates"
                    },
                    "ColourGroup": {
                        "Name": "White"
                    },
                    "Style": {
                        "Name": "Medium"
                    },
                    "JoinType": {
                        "Name": "Mitre"
                    },
                    "Image": {
                        "FileName": "1403 WHITE PEARL WOOD.jpg",
                        "FileSize": "0"
                    },
                    "BusinessUnit": {
                        "Name": null
                    }
                },
    

    Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

  • sudderssudders Posts: 8Questions: 2Answers: 0
    edited December 2015

    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

    {
        "draw": null,
        "data": [{
                    "DT_RowId": "row_a60de9a1-fd91-e511-beba-00c2c60bffc1",
                    "Product": {
                        "ProductTypeId": "9",
                        "ColourGroupId": "11",
                        "StyleId": "3",
                        "JoinTypeId": "1",
                        "BusinessUnitId": null,
                        "ImageId": 1,
                        "DefaultDisplayCode": "1403",
                        "RenderCode": "1403",
                        "DefaultDisplayName": "White Pearl Wood",
                        "Width": 1219,
                        "Depth": 2438,
                        "HasBlackEdge": false,
                        "TextureFile": "1403 WHITE PEARL WOOD.jpg",
                        "IsActive": false
                    },
                    "ProductType": {
                        "Name": "Laminates"
                    },
                    "ColourGroup": {
                        "Name": "White"
                    },
                    "Style": {
                        "Name": "Medium"
                    },
                    "JoinType": {
                        "Name": "Mitre"
                    },
                    "Image": {
                        "FileName": "1403 WHITE PEARL WOOD.jpg",
                        "FileSize": "0"
                    },
                    "BusinessUnit": {
                        "Name": null
                    },
                    "Finish": []
                },
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    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

  • PinPoint VisualisationPinPoint Visualisation Posts: 1Questions: 0Answers: 0

    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

This discussion has been closed.