Optional add () for many-to-many connection

Can I add multiple of the same objects to a many-to-many connection? The current setup I'm running gives me Error: Trying to '.add()' an instance which already exists!

every time I try to add a speaker multiple times. For example, perhaps speaker X speaks for 20 minutes, speaker Y takes over, and then its speaker X: s turns again. How can I solve this?

this is my event model:

attributes: {
   id: {
     type: "integer",
     primaryKey: true,
     autoIncrement: true
   },
   name: {
     type: "string",
     required: true
   },
   speakers: {
     collection: "speaker",
     via: 'events',
     dominant: true
   }
},
addSpeaker: function (options, cb) {
   Event.findOne(options.id).exec(function (err, event) {
     if (err) return cb(err);
     if (!event) return cb(new Error('Event not found.'));
     event.speakers.add(options.speaker);
     event.save(cb);
});

      

And also the speaker model:

attributes: {
name: {
  type: "string",
  required: true
},
title : {
  type: "string"
},
event: {
  model: "event"
},
events: {
  collection: "event",
  via: "speakers"
}
}

      

+3
sails.js waterline


source to share


No one has answered this question yet

Check out similar questions:

3
sails on return put RangeError: max call stack size exceeded and crash
3
Sails Association 0.10 does not fill
2
Creating a waterline model
1
Sails Blueprint adds Many-to-Many entry
0
Can the controller for each "res.json (item)" use sockets.io?
0
How can I check my Sails.js unique email attribute with Wolfpack.js?
0
Sailsjs / Passport add fields to user
0
How to generate a hash password and store it in a database in sails.js file
0
Sails min, max, minLength, maxLength for number and string types gives userError
0
Get count of related posts in sailsjs



All Articles
Loading...
X
Show
Funny
Dev
Pics