Skip to content

Need a way to query associated object's attributes #5472

@gregorypierce

Description

@gregorypierce

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:

  1. Find the owner who has an emailAddress == "foo@bar.com" and get that persons id
  2. 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"})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions