ucast
ucast copied to clipboard
Support conditions that use nested relations
It seems that sql interpreter doesn't support conditions with nested relations.
Indeed the condition o { operator: 'eq', value: 2, field: 'x.y.z' }
is translated into WHERE 'x'.'y.z' = :1
.
Are you planning to support this type of conditions?
The functionality to support relations is implemented through 2 options:
- In case, there is a dot in a field name
options.joinRelation
is called to determine whether it's a relation. - If it's a relation, then ucast calls
options.foreignField
callback to determine the name of the Ifrelated field in SQL - If it's not a relation, ucast calls
options.localField
. By default, it just escapes a column but you can implement a logic that checks if the column is of JSON type then convert it to JSON expression (e.g., JSONB expression in Postgress)
I tested this functionality only for direct relations (and not for relations of relations - i.e., deeper relations). After that, I just haven't had to time look again at this functionality. As currently, this is not on my priority list. And very likely, I will look into it only in the next year
Hi, sorry for the late reply.
I took a look at these functions. It seems that Query
class and ORM adapters need some adjustments to support deeper relations.
If I have time, I'll try to raise a PR.
Thank you!
I've made some changes to the typeorm adapter and the Query class in order to add this functionality. Unfortunately I have no experience with the other ORMs and I can't be sure that my changes don't affect the other adapters.
Here's my changes if someone need it as a starting point for a patch: https://github.com/ccatterina/ucast/commit/086d9fe3dd07a83ae20a9bafeb3aa6590bd8c63c