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

Relationships should honor lessThan and greaterThan between attributes #190

Open
nikhilnanivadekar opened this issue Jan 2, 2019 · 5 comments

Comments

@nikhilnanivadekar
Copy link
Contributor

A relationship like this should work:

<Relationship name='pets' relatedObject='Pet' cardinality='one-to-many'>
<![CDATA[this.personId = Pet.personId and
this.age > Pet.age]]>
</Relationship>

If it is invalid then there should be build time exception. Instead, currently the build succeeds and the query generated is Person.personId = Pet.personId which is incorrect.
Please correct me if I am doing something wrong.

@mohrezaei
Copy link
Collaborator

That's not considered a proper relationship and should throw at build time.

@nikhilnanivadekar
Copy link
Contributor Author

Why is it not a proper relationship? In this case, I only want those Person objects which have Pet objects with ages less than the owner's age. Imperative way to do it will be to deep-fetch and then do the greater than check which I think is inefficient.
If there is a better way than that, please let me know.

@mohrezaei
Copy link
Collaborator

In almost all cases, non-equi joins used for relationships are confused with query semantics.

I only want those Person objects which have Pet objects with ages less than the owner's age.

Sounds like you're doing a query to get Persons, not defining how Person and Pet relate to each other. That should not require a relationship, just a query. Relationships are not hard-coded queries. If you want Persons, that should start with PersonFinder, not PetFinder+deep fetch.

@nikhilnanivadekar
Copy link
Contributor Author

I do not know how to do this without a relationship and with just Finders.

SELECT A.* from PERSON A, PET B
WHERE A.PERSON_ID = B.PERSON_ID
AND A.AGE > B.AGE

@mohrezaei
Copy link
Collaborator

PersonFinder.age().greaterThan(PersonFinder.pets().age()). Note that greaterThan is not implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants