Exp on relationship IDs

38 views
Skip to first unread message

Anthonin Lizé

unread,
Oct 7, 2022, 6:02:10 AM10/7/22
to Agrest Framework User Group
Hi all,

Me again.
Since I switched to AgRest 5.x, everything works fine, except one backward compatibility, I suppose.
I had query expressions filtering on a relationship ID that does not work anymore.
Example:
entity0 (ID, entity1_id)
entity1 (ID, attr1)
 exp = entity1.id in (1,2,3)

The generated query (Oracle - JDBC adapter) is incorrect, something like:
select distinct t0.*
from entity0 t0
join entity1 t1 on t0.entity1_id = t1.id
where t0.id in (1,2,3)

The where clause on ID is applied to t0, not t1.
If I changed the expression to attr1 of entity1, it works as expected.

Same thing happens on other entities, even going through M-to-N relationships:
entity0 (ID)
entity1 (entity0_id, entity2_id)
entity2 (ID)

  exp = entity1s.entity2.id in (1,2,3)
would result in
select distinct t0.*
from entity0 t0
join entity1 t1 on t0.entity1_id = t1.id
join entity2 t2 on t2.id = t1.entity2_id
where t0.id in (1,2,3)

This would however work fine:
  exp = entity1s.entity2_id in (1,2,3)
would result in
select distinct t0.*
from entity0 t0
join entity1 t1 on t0.entity1_id = t1.id
where t1.entity2_id in (1,2,3)

Any insight?

Thanks a lot
Anthonin

Andrus Adamchik

unread,
Oct 28, 2022, 4:48:10 AM10/28/22
to Agrest Framework User Group
Hi Anthonin,

I usually filter on the relationship itself, not on the target ID. I.e. instead of "entity1.id in (1,2,3)", I'd do "entity1 in (1,2,3)". Could you try this and see if it makes a difference.

In the meantime will need to investigate why your syntax generates broken SQL...

Andrus

--
You received this message because you are subscribed to the Google Groups "Agrest Framework User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to agrest-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/agrest-user/CACT4rJx5qn-ghLjNN5Ok%3DPa4NSxskFdyOjFD3AqUGidMOuxX2A%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages