javascript - Adding duplicates to SailsJS model with many-to-many association -
i have 2 models, items , order, have many-to-many association. i've been trying past 5 hours figure out way add multiple items objects order including duplicates.
if items unique works fine, if try this:
order.items.add([12, 13, 12, 12]); order.save();
it save 12, 13. duplicates ignored, not if want order more 1 of item.
any suggestions helpful.
many-to-many association in db scheme creating relation between record table record table, of course unique, because 12
has association order
record.
the solution is, use model achieve that. example, in models
folder:
order.js
module.exports = { attributes: { items : {collection: 'orderitem', via: 'order'} } };
orderitem.js
module.exports = { attributes: { order : {model: 'order'}, item : {model: 'item'} } };
item.js
module.exports = { attributes: { } };
so order
model, can add orderitem
model represent relation between order
, item
, , orderitem
unique in order
point of view though item under it's record may same.
Comments
Post a Comment