Selection by Mjoin condition
Selection by Mjoin condition

How to make a selection in the server-side handler based on the mjoin connection condition, i.e. by the presence of an entry in the attached table?
This discussion has been closed.
How to make a selection in the server-side handler based on the mjoin connection condition, i.e. by the presence of an entry in the attached table?
Replies
I'm afraid I don't quite understand. How is what you are looking for different from this example?
Thanks,
Allan
I'll try to explain with this example. I need to select only those records from the "users" table for which there are related records in the "user_permission" table.
Oh I see - so if there aren't any permissions for a given user, you wouldn't show them in the list. Only users with permissions would be shown?
That isn't something that the Mjoin class has the ability to do I'm afraid (since it is effectively a left join to the array of "many" data).
However, what you could do is filter out the rows which don't have any permissions. That could be done either with
column().search()
(if you wanted to show that some records had been filtered out) orajax.dataSrc
if you want to remove them before DataTables sees the data.Allan
Right but you could use a left join in addition and achieve the desired effect like this. This way you won't see users that don't have a permission for anything.
@allan
I remember discussing the necessity of SELECT DISTINCT with you some time ago. You were not convinced. But now I can see more clearly why this is really needed: If you want to check the existence of a child record through a left join with checking for null values (to imitate an inner join) zero, one or more child records may exist. If more than one child record exists you will have multiple parent table records returned even though you don't even have a child record field in the field list!
I could mitigate this using "array_values(array_unique ..." etc. but that shouldn't be the final solution. In my opinion this is a clear case for SELECT DISTINCT to be implemented in Editor.
To avoid the issues with the left join and the requirement of SELECT DISTINCT here is another way to achieve the same result and avoid duplicate parent table records:
Thank you so much. Everything works