Dynamic Gets with WHERE statement on join table doesn't work #500
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: joomla/Component-Builder#500
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Hi
When I use a dynamic get and build a query with joins, and use a join table in my where statement, then the compiler doesn't add it to the model. It simply skips.
If I target the primary table, e.g.
a.first_name = \'Super\'
then the where statement is added to the model. But I can't target a join table in my where statement. Is this a bug perhaps?Steps to reproduce the issue
Build a query with joins and add a where statement on the join table
Expected result
Where statement added to the model query
Actual result
Where statement not added to the model query
System information (as much as possible)
Additional comments
Well currently the JOINT options only allow for field to field relationship, not field to string.
So if you look at the hint you see that the On Field and Join Field are both having table field notation.
If you would like to filter the relationship, you must use the Tweak tab Filter subform as Filter Type >
FunctionVar
and State Key >$supper
and Table Key >a.first_name
To set the
$supper
var, use the Custom Script tab, testing which PHP area gets inserted before the query is made.Maybe I didn't explain it well enough.
It's not in the join, but in the WHERE statement in the tweak tab I'm having an issue. And using a string here works fine, if I do it on the main table (a.columnname) - just not for any field coming from a join table (e.g. b.columnname). And that's the issue...
Okay let me try on my side and see if I get the same issue. One moment!
Okay so have a look at this quick trace... let me know https://youtu.be/a4j8yn9SCt4 (give google a few minutes to process the video)
Thank you for your video. I also have a video for you :-)
Please take a look here: https://www.youtube.com/watch?v=fL-HUUC6kpg
For some reason, unknown to me, the WHERE statement works with my main table, and first two join tables, but not on the third table. The query is valid and is returning data - also for the third table. So the only thing I can think of, is an issue using multiple joins beyond 2 join tables???
I think I know what the issue is, currently JCB is not able to like the d table with the a and so the filter is lost, it is not due to the limit of the number of joints, I have many joins in many projects and they work in filtering just fine. But they all hold direct relationship with the a table, yet you have it related to the c table. This seems to be the cause of the limitation. Now we can try and fix this, but the way I build the DynamicGet query builder has made it very fast, but also crazy complex.
So before I jump in and try to improve this, can you just check the above, try linking your third joint to a and see if the filter for table d gets added.
Since if we can indeed establish that it is due to its relationship to c instead of a that the filter is dropped, I can at least know where to start.
It did. Funny though. If I changed it so that my where statement was: if c.field_id = a.id it didn't work. But if a.id = c.field_id it worked. So the order also seem to matter.
So this is not a bug, it is just a limitation in JCB. Maybe not the expected behavior, but looking at the code it is doing what it was written to do. I can try and improve this, give me a few days.
Then if you turn the order around the relation is lost, the fields are named On Field and Join Field and this is important to keep in mind. Since ON targets the main field, and JOIN the join tables target field, you can't turn them around.
Now we know that the query gets added correctly so it is just the WHERE filter that gets missed. So I will just make sure the filters get correctly channeled.
So this means as On Field->
c.field_id
and Join Field->a.id
can never exist since the a table is never a Joint table.Okay this was bugging me so I added the correct behavior, please test this improvement in latest push to staging branch.
It it working for me now :-) Awesome.
Thank you!