ColdBox ORM Module
Search…
Associations
Yes, you can also create associations in Detached Criteria Builder, just like you would with Criteria Builder. Go on, make some uber-complicated queries!
Here we go!...
You can also navigate associations by nesting the criterias using the createCriteria("association_name") method and then concatenating the properties of the association to query upon. You will basically be switching the pivot point of the query.
1
var c = newCriteria("User");
2
var users = c.like("name","lui%")
3
.createCriteria("admins")
4
.like("name","fra%")
5
.list();
Copied!
1
var c = newCriteria("User");
2
var users = c.like("name","lui%")
3
.withAdmins().like("name","fra%")
4
.list();
Copied!
You can also use a hibernate property approach which aliases the association much how HQL approaches it by using the createAlias("associationName","alias") method:
1
var c = newCriteria("User");
2
var users = c.like("name","lui%")
3
.createAlias("admins","a")
4
.eq("a.name","Vero")
5
.list();
Copied!
Let's see the method signatures for these guys:
1
createCriteria(required string associationName,numeric joinType)
2
createAlias(required string associationName, required string alias, numeric joinType)
3
with{AssociationName}( joinType )
Copied!
Last modified 3yr ago
Copy link