Skip to content

hasOne query based on referenced table #190

Description

@Locke

I have a hasOne relationship and want to query based on the referenced table.

var Person = db.define('person', {
    name : String
});
var Animal = db.define('animal', {
    name : String
});
Animal.hasOne("owner", Person); // creates column 'owner_id' in 'animal' table

I want to do do something like:

SELECT * FROM animal JOIN person ON animal.owner_id = person.id WHERE person.name = "John";

Any ideas how I can achieve this? In the drivers there is opts.merge that seems to be exactly what I am searching for, but I can not find any documentation of it.

I already tried to pass find the options "__merge" and "extra", but ended up in a rather complex statement and failed to pass the condition.

It would be great if I could just do:

Animal.find(owner: Person.find("name": "John"))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions