goldmansachs/reladomo

Relationships should honor lessThan and greaterThan between attributes

nikhilnanivadekar opened this issue · 5 comments

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.

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

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.

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.

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

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