javascript - How to nest Sequelize associations? -
i trying nest associations using node/sequelize/postgresql. common scenario (i believe), have yet determine how it. here scenario.
person
-- location (1:m)
----- sublocation (1:m)
the person model has belongstomany association working great. have personlocation table holds ids of both person , location , location(s) returned person query.
here's gets tricky. need associate personlocation sublocation needs 1:m relationship.
person.belongstomany(location, {through: 'personlocation'});
--this how envision work, since defined personlocation association, cannot access way.
personlocation.belongstomany(sublocation, {through: 'personlocationsublocation'});
the person have 1:m locations, each of locations have multiple 1:m sublocations. when doing query on person, want see person/locations/sublocations person.
the database
person
id
name
location
id
name
sublocation
id
name
personlocation
id
personid
locationid
personlocationsublocation
id
personlocationid
sublocationid
any ideas how achieve using sequelize?
sequelize-embed
easily insert , update sequelize models nested associations
Comments
Post a Comment