Editor: MJoin Error: Join was performed on the field x which was not included... - Page 2

Editor: MJoin Error: Join was performed on the field x which was not included...

2»

Answers

  • EisenkieferEisenkiefer Posts: 12Questions: 2Answers: 0
    edited November 2016

    Heres the code, I got the error with:
    ("Join was performed on the field 'TableA.B_FK' which was not included in the Editor field list. The join field must be included as a regular field in the Editor instance.")

    MVC Controller:

    public ActionResult MyEditor()
            {
                var settings = Properties.Settings.Default;
                var formData = HttpContext.Request.Form;
               using (var db = new Database(settings.DbType, GeneralHelpers.GetConnectionString(((string[])Session["Permissions"])[0])))
                {
                    var response = new Editor(db, "TableA", "TableA.ID")
                        .Model<TableAModel>()
    
                        .Field(new Field("TableA.ID").Set(false))
                        .Field(new Field("TableA.B_FK").Set(false))
                        .Field(new Field("TableB.ID").Set(false))
    
                        .LeftJoin("TableB", "TableA.B_FK", "=", "TableB.ID")
                        .MJoin(new MJoin("TableC")
                            .Model<TableCModel>()
                            .Link("TableA.B_FK","TableC.B_FK")
                            .Order("TableC.ID")
                        )
                         
                         
                        .Process(formData)
                        .Data();
    
                   return Json(response, JsonRequestBehavior.AllowGet);
                }
            }
    

    TableAModel:

    public class TableAModel : DataTables.EditorModel
        {
    
            public class TableA
            {
                public int ID { get; set; }
                public string B_FK { get; set; }
                public string ColA{ get; set; }
                public string ColB{ get; set; }
                public string ColC{ get; set; }
                public string ColD{ get; set; }
                public string ColE{ get; set; }
                public string ColF{ get; set; }
                public string ColG{ get; set; }
            }
            public class TableB
            {
                public int ID { get; set; }
                public string ColA{ get; set; }
                public int ColB{ get; set; }
            }
    }
    

    TableCModel:

     public class TableCModel : DataTables.EditorModel
        {
            public int B_FK { get; set; }
            public string ColA{ get; set; }
            public string ColB{ get; set; }
            public string ColC{ get; set; }
        }
    

    Already tried any suggested steps described above - nothing helped.
    What I also tried:
    Replacing the LeftJoin by another MJoin doesn't help aswell.
    MJoining by Table_B.ID = TableC.B_FK (same error).
    Adding all fields by .Field(new Field(...)) (also without the .Set(false))

    Columns are displayed properly - and since we inject a custom data set, data is displayed but not editable. (Already deactivated this to receive the default DataTables DataSet - this didn't help aswell.)

    Hope this helps your investigation.

    Cheers
    Eisenkiefer

  • EisenkieferEisenkiefer Posts: 12Questions: 2Answers: 0

    Hi,

    can I expect this to be fixed until the end of the week?
    This feature is mandatory for my use-case, I have to look for another library otherwise.

    Eisenkiefer

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    I'm planning to look into this in detail tomorrow. Will let you know what I find then.

    Allan

  • EisenkieferEisenkiefer Posts: 12Questions: 2Answers: 0

    Alright, thanks.

    Eisenkiefer

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    It turns out not to be exactly the issue I thought it was, but rather one related to using leftJoin with a many join together in the same Editor instance. I don't have a fix for that today I'm afraid, but it is the issue that I am now working on and should be able to make some process now that the problem has been identified.

    Regards,
    Allan

  • EisenkieferEisenkiefer Posts: 12Questions: 2Answers: 0

    Well, at least thats good news.

    Can I expect this to be fixed until the end of the week?
    Or do you have an idea how long the work will take?

    Thanks,
    Eisenkiefer

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    @Eisenkiefer - I've just sent you a PM.

    Allan

  • EisenkieferEisenkiefer Posts: 12Questions: 2Answers: 0
    edited November 2016

    The join error is gone.

    Now getting an error that the fields (parameters) in TableC couldnt be found.
    XHR Response for the Tables differ, columns of left joined tables are written in the JSON flat - MJoined tables are written as an Array. Here's an example:
    {draw: null, data: [
    {DT_RowId: "row_2878",
    TableA: { ID: 1, B_FK: 2, ColA:"a",...},
    TableB: { ID: 2, ColA:"a",...},
    TableC: [ {ID:2, ColA:"a",...} ]
    },...],...}
    Might that be the Problem?

    If I change the response.data to a custom dataset, causing all data written into the JSON flat (like TableA and TableB), the Editor works inline.
    If I open the edit dialog I get the error "Object reference not set to an instance of object." (at least something in that meaning, as I had to translate it)

    Regards,
    Eisenkiefer

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    Could you copy and paste the error message you are getting exactly for me please?

    The reason TableC in the above is an array is that you have used an Mjoin for TableC - i.e. one-to-many. It is expected that it would have many records, and that needs to be in an array.

    Allan

  • EisenkieferEisenkiefer Posts: 12Questions: 2Answers: 0
    edited November 2016

    Sure it's,
    "Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt." (German)
    Seems to be a null reference,
    correct translation should be:
    Object reference not set to an instance of object.

    It's located in the bottom of the edit dialog box. Left of the "Update" button.

    Eisenkiefer

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    Thanks for the information/ I've not been able to look into it today, but will do tomorrow.

    Allan

  • allanallan Posts: 61,822Questions: 1Answers: 10,127 Site admin

    Could you add:

    TryCatch( false )
    

    immediately after the new Editor() code please (i.e. add it into the chain)? That will disable Editor's try / catch during the data processing and allow the debugger to zero in on exactly where the error is occurring.

    If you then run it, what does it tell you? Hopefully it will identify the line of code where the error is.

    Also, could you show me the data that is being submitted to the server please (using your browser's developer tools - the "Header" tab for the XHR in question will show that)?

    Unfortunately I haven't been able to reproduce the error here yet, so hopefully the above information will let me identify what is going wrong.

    Thanks,
    Allan

This discussion has been closed.