是否可以将多个同一对象添加到多对多连接中?我正在运行的当前设置每次尝试多次添加扬声器时都会给我Error: Trying to '.add()' an instance which already exists!
。例如,扬声器X说话20分钟,扬声器Y接管,然后扬声器X再次转动。我该如何解决这个问题?
这是我的活动模型:
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);
});
还有扬声器模型:
attributes: {
name: {
type: "string",
required: true
},
title : {
type: "string"
},
event: {
model: "event"
},
events: {
collection: "event",
via: "speakers"
}
}