If an object has an associated collection, it is not clear how (or even if its possible) to query into that associated object stuff.
Pet has an Owner
Owner has an emailAddress
How do I select all of the Pets whose owner has an emailAddress == "foo@bar.com"
While its easy to do 2 queries to accomplish this:
- Find the owner who has an
emailAddress == "foo@bar.com" and get that persons id
- Find all Pets who have the
id from query 1
It seems that there would be a better syntax for this:
Pet.findAll({ "owner.emailAddress" : "foo@bar.com" })
Now whether or not this is internally optimized or just syntactic sugar doesn't matter, its much easier to read and write.
Further, if a Pet has a breed how would I select the email addresses of all of the owners whose Pet.breed == "beagle"
Owner.findAll({"pet.breed" : "beagle"})