Fix option propagation in relation methods
- EmbedsMany.prototype.remove - EmbedsMany.prototype.add
This commit is contained in:
parent
b781dae339
commit
121afda79b
|
@ -2931,11 +2931,11 @@ EmbedsMany.prototype.add = function(acInst, data, options, cb) {
|
|||
var modelTo = this.definition.modelTo;
|
||||
var modelInstance = this.modelInstance;
|
||||
|
||||
var options = definition.options;
|
||||
var belongsTo = options.belongsTo && modelTo.relations[options.belongsTo];
|
||||
var defOpts = definition.options;
|
||||
var belongsTo = defOpts.belongsTo && modelTo.relations[defOpts.belongsTo];
|
||||
|
||||
if (!belongsTo) {
|
||||
throw new Error('Invalid reference: ' + options.belongsTo || '(none)');
|
||||
throw new Error('Invalid reference: ' + defOpts.belongsTo || '(none)');
|
||||
}
|
||||
|
||||
var fk2 = belongsTo.keyTo;
|
||||
|
@ -2952,7 +2952,7 @@ EmbedsMany.prototype.add = function(acInst, data, options, cb) {
|
|||
belongsTo.modelTo.findOne(filter, options, function(err, ref) {
|
||||
if (ref instanceof belongsTo.modelTo) {
|
||||
var inst = self.build(data || {});
|
||||
inst[options.belongsTo](ref);
|
||||
inst[defOpts.belongsTo](ref);
|
||||
modelInstance.save(function(err) {
|
||||
cb(err, err ? null : inst);
|
||||
});
|
||||
|
@ -2978,11 +2978,11 @@ EmbedsMany.prototype.remove = function(acInst, options, cb) {
|
|||
var modelTo = this.definition.modelTo;
|
||||
var modelInstance = this.modelInstance;
|
||||
|
||||
var options = definition.options;
|
||||
var belongsTo = options.belongsTo && modelTo.relations[options.belongsTo];
|
||||
var defOpts = definition.options;
|
||||
var belongsTo = defOpts.belongsTo && modelTo.relations[defOpts.belongsTo];
|
||||
|
||||
if (!belongsTo) {
|
||||
throw new Error('Invalid reference: ' + options.belongsTo || '(none)');
|
||||
throw new Error('Invalid reference: ' + defOpts.belongsTo || '(none)');
|
||||
}
|
||||
|
||||
var fk2 = belongsTo.keyTo;
|
||||
|
|
Loading…
Reference in New Issue