I am trying to use Sails query language to query two tables, with Postgresql as the database.
I have two tables 'Person' and 'Pet'.
For 'Person', its model is:
id: { type: 'integer', primaryKey }
namePerson: { type: 'string' }
age: { type: 'integer' }
For 'Pet', its model is:
id: { type: 'integer', primaryKey }
owner: { model: 'Person' }
namePet: { type: 'string' }
I want to find all the pets who are owned by people younger than 12, and I want to do it in a single query. Is that possible?
I only know how to do it in two queries. First, find all the people who are younger than 12:
Person.find({age: {'<', 12}}).exec(function (err, persons) {..};
Then, find all the pets owned by them:
Pet.find({owner: persons}).exec( ... )