Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support conditions that use nested relations #32

Open
ccatterina opened this issue Oct 13, 2021 · 3 comments
Open

Support conditions that use nested relations #32

ccatterina opened this issue Oct 13, 2021 · 3 comments
Labels
question Further information is requested

Comments

@ccatterina
Copy link
Contributor

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?

@ccatterina ccatterina changed the title Support condition that use nested relations Support conditions that use nested relations Oct 13, 2021
@stalniy
Copy link
Owner

stalniy commented Oct 14, 2021

The functionality to support relations is implemented through 2 options:

  1. In case, there is a dot in a field name options.joinRelation is called to determine whether it's a relation.
  2. If it's a relation, then ucast calls options.foreignField callback to determine the name of the Ifrelated field in SQL
  3. 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

@stalniy stalniy added the question Further information is requested label Oct 14, 2021
@ccatterina
Copy link
Contributor Author

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!

@ccatterina
Copy link
Contributor Author

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:
ccatterina@086d9fe

ccatterina pushed a commit to ccatterina/ucast that referenced this issue Aug 26, 2022
Add support for fields with nested relations (multiple levels) in the
typeORM adapter.

The other adapters treat these fields as simple fields and they don't
join the relations.

Fix issue stalniy#32 for TypeORM adapter.
ccatterina pushed a commit to ccatterina/ucast that referenced this issue Aug 26, 2022
Add support for fields with nested relations (multiple levels) in the
typeORM adapter.

The other adapters treat these fields as simple fields and they don't
join the relations.

Fix issue stalniy#32 for TypeORM adapter.
ccatterina added a commit to ccatterina/ucast that referenced this issue Aug 26, 2022
Add support for fields with nested relations (multiple levels) in the
typeORM adapter.

The other adapters treat these fields as simple fields and they don't
join the relations.

Fix issue stalniy#32 for TypeORM adapter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants