Enhancement 385 : ENH: Consider query syntax for multiple joins to the same OneToMany relationship
Priority 
High
Reported Version 
 
Logged By 
Rob
Status 
Fixed
Fixed Version 
github
Assigned To 
 
Product 
Ebean - core
Duplicate Of 
 
Created 
20/03/2012
Updated 
20/03/2012
Type 
Enhancement
 
Attachments 
No attachments

Consider the following syntax (or something similar, the assignment of a specific alias is the key):

Query query =
Ebean.find(Asset.class)
.join("attributes", "attributes.definitionId, attributes.value", "a1")
.join("attributes", "attributes.definitionId, attributes.value", "a2")
.where()
.eq("a1.definitionId", 57L)
.eq("a1.value", "Quux")
.conjunction()
.eq("a2.definitionId", 56L)
.eq("a2.value", "Foo")
.query();

 
Rob 20 Mar 10:08
The intended SQL

> So, I need to have multiple inner joins on the same column, like so:
>
> SELECT DISTINCT(ass.a_id)
> FROM assets ass
> INNER JOIN attributes a1 on ass.a_id = a1.att_a_id
> INNER JOIN attributes a2 on ass.a_id = a2.att_a_id
> WHERE (a1.att_s_id = :defId1 AND a1.att_value = :val1) AND
> (a2.att_s_id = :defId2 AND a2.att_value = :val2)

woResponse

Upload a file