Using mjoin for linked table with extra condition (C#)

Using mjoin for linked table with extra condition (C#)

gjwestenenggjwesteneng Posts: 5Questions: 2Answers: 0

The case is I have a table workgroup and a table workplace. I want to assign workplaces to a workgroup. For this I make a link table, workplaceworkgroup, with an idworkgroup and an idworkplace. This works fine, here's the code:

            var response = new Editor(db, "Workgroup")
                .Model<DataTables_LinkWorkgroup>()
                    .MJoin(new MJoin("Workplace")
                        .Link("Workgroup.id", "WorkplaceWorkgroup.IdWorkgroup")
                        .Link("Workplace.id", "WorkplaceWorkgroup.IdWorkplace")
                        .Model<DataTables_LinkWorkplace>()
                        .Field(new Field("id")
                            .Options("Workplace", "id", "Name")
                        )
                    )
                    .Process(request)
                    .Data();

In the webpage the user sees all workgroups and when editing one he gets a checkbox dropdown list with all workplaces.

Now I want to extend this. Both Workgroup and Workplace also have a field IdSite. If the user edits a Workgroup for IdSite 3, I only want him to see the Workplaces with IdSite == 3 in the checkbox dropdown.

So I would change the code above to something like this:

            var response = new Editor(db, "Workgroup")
                .Model<DataTables_LinkWorkgroup>()
                    .MJoin(new MJoin("Workplace")
                        .Link("Workgroup.id", "WorkplaceWorkgroup.IdWorkgroup")
                        .Link("Workplace.id", "WorkplaceWorkgroup.IdWorkplace")
                        .Link("Workplace.IdSite", "Workgroup.IdSite")
                        .Model<DataTables_LinkWorkplace>()
                        .Field(new Field("id")
                            .Options("Workplace", "id", "Name")
                        )
                    )
                    .Process(request)
                    .Data();

So a third link condition to match the IdSite. That doesn't work, it gives an error that at most 2 link's are allowed.
Other way I thought of was to add a where("IdSite", "3"), but that only works for Workgroup, I can't get the Workplaces to get filtered on IdSite.

Any ideas?

Thanks in advance!

Answers

  • gjwestenenggjwesteneng Posts: 5Questions: 2Answers: 0

    Am I the only one with this issue?

  • allanallan Posts: 63,516Questions: 1Answers: 10,472 Site admin

    Hi,

    Sorry I missed your post before. I'm sorry to say that there is currently no option to do what you are looking for. You can apply a WHERE condition directly to the Mjoined table - but there is no way to specify three link options.

    Allan

This discussion has been closed.