Mjoin Direct Link Help

Mjoin Direct Link Help

matt_rumsey1212matt_rumsey1212 Posts: 51Questions: 8Answers: 0
edited November 2015 in Free community support

Hi,

So I am absolutely loving DataTables. I am however running out of ideas when trying to use MJoin. I have a Table representing teams which makes use of the details-control to display child rows. Within these child rows I would like to display a list of Agent names which are associated with the Parent Teams. When using MJoin I keep receiving the error that "DataTables Warning: Table ID = Team: Join was performed on the field 'Team.Id' which was not included in the Editor field list. The join field must be included in the regular Editor instance'.

This makes perfect sense to me apart from the fact that I have included Team.Id as a field in the regular Editor Instance. After scouring the forums I cannot seem to make sense of it. The code from my ActionResult is below. Any help would be greatly appreciated.

EDIT: The LeftJoin used within this is seperate from the current problem and represents a single agent who is the team leader. This seems to work perfectly.

public ActionResult TeamsTable()
        {
            var settings = EditorGenerator.Properties.Settings.Default;
            var formData = HttpContext.Request.Form;

            using (var db = new Database(settings.DbType, settings.DbConnection))
            {
                var response = new Editor(db, "Team")
                    .Model<TeamModel>()
                    .Field(new Field("Team.Id")
                    )
                    .Field(new Field("Team.Name")
                    )
                    .Field(new Field("Team.IsActive")
                    )
                    .Field(new Field("Team.TeamLeader_id")
                        .Options("Agent", "Id", "Surname")
                    )
                    .LeftJoin("Agent", "Agent.Id", "=", "Team.TeamLeader_id")
                    .MJoin(
                        new MJoin("Agent")
                            .Model<AgentModel>()
                            .Link("Team.Id", "Agent.Team_id")
                            )
                    .Process(formData)
                    .Data();

                return Json(response, JsonRequestBehavior.AllowGet);
            }
        }

Answers

  • allanallan Posts: 63,871Questions: 1Answers: 10,525 Site admin

    Hi,

    Thanks for posting your question - sorry to hear you are having problems with this.

    Two questions:

    1. Could you confirm what version of Editor you are using? Editor 1.5.2 is now available - although it doesn't contain any changes in this area, so I don't think it will fix an issue if there is on in 1.5.1.
    2. Do you get this error immediately when loading the data for the page, or is on a submit?

    Thanks,
    Allan

  • matt_rumsey1212matt_rumsey1212 Posts: 51Questions: 8Answers: 0

    I am currently using 1.5.1. Shall update that now and report back.
    Also, the error is the standard chrome dialog upon page load so no data is displayed. Commenting out the Mjoin code allows the rest of the data to load correctly. Thankyou for the quick reply.

  • matt_rumsey1212matt_rumsey1212 Posts: 51Questions: 8Answers: 0

    Updating to 1.5.2 didn't solve the problem as you predicted

  • allanallan Posts: 63,871Questions: 1Answers: 10,525 Site admin

    Is new Field("Team.Id") your primary key for the Team table? If so, could you try removing that field (including the primary key isn't required) and change the line var response = new Editor(db, "Team") to be:

     var response = new Editor(db, "Team", "Id")
    

    Regards,
    Allan

  • matt_rumsey1212matt_rumsey1212 Posts: 51Questions: 8Answers: 0
    edited November 2015

    Yes indeed Team.Id is the primary key. So this has created a new error upon page load. It now displays:

    "DataTables warning id=Team. An item with the same key has already been added"

    Commenting out the MJoin code stops this new error and loads the remaining data as expected. Thankyou once again for all your help so far.

    Any ideas as to why this new error is now produced?

  • allanallan Posts: 63,871Questions: 1Answers: 10,525 Site admin

    I suspect it will be related to the left join and MJoin both using Agent. I don't see Agent being used in the field list though - is it defined in your model? What you could try is to add an alias for the left join:

    .LeftJoin("Agent as A",  ...
    

    and update all the suitable Agent references to be A (i.e. for the MJoin it uses Agent for the left join it uses A - otherwise there is a conflict).

    Regards,
    Allan

  • matt_rumsey1212matt_rumsey1212 Posts: 51Questions: 8Answers: 0

    Will get back to you as soon as I can on this. Been put on to something else for the last couple of days.

  • allanallan Posts: 63,871Questions: 1Answers: 10,525 Site admin

    No problem - I know that feeling ;-)

    Allan

  • matt_rumsey1212matt_rumsey1212 Posts: 51Questions: 8Answers: 0

    An update on this. The screen I was working on ended up being redesigned meaning that mjoin was not needed in this case. However, thankyou for all your help regarding this subject.

This discussion has been closed.