You need to specify that a Family
has several Person
s. See the documentation on has n
and belongs_to
.
class Family
include DataMapper::Resource
property :id, Serial
property :nice, Boolean
# add this:
has n, :people
end
Then you can use this:
Family.all(:nice => true).people
The SQL generated is actually a subquery rather than a join:
SELECT "id", "family_id" FROM "people" WHERE "family_id" IN (SELECT "id" FROM "families" WHERE "nice" = 't') ORDER BY "id"