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 modelTo = this.definition.modelTo;
|
||||||
var modelInstance = this.modelInstance;
|
var modelInstance = this.modelInstance;
|
||||||
|
|
||||||
var options = definition.options;
|
var defOpts = definition.options;
|
||||||
var belongsTo = options.belongsTo && modelTo.relations[options.belongsTo];
|
var belongsTo = defOpts.belongsTo && modelTo.relations[defOpts.belongsTo];
|
||||||
|
|
||||||
if (!belongsTo) {
|
if (!belongsTo) {
|
||||||
throw new Error('Invalid reference: ' + options.belongsTo || '(none)');
|
throw new Error('Invalid reference: ' + defOpts.belongsTo || '(none)');
|
||||||
}
|
}
|
||||||
|
|
||||||
var fk2 = belongsTo.keyTo;
|
var fk2 = belongsTo.keyTo;
|
||||||
|
@ -2952,7 +2952,7 @@ EmbedsMany.prototype.add = function(acInst, data, options, cb) {
|
||||||
belongsTo.modelTo.findOne(filter, options, function(err, ref) {
|
belongsTo.modelTo.findOne(filter, options, function(err, ref) {
|
||||||
if (ref instanceof belongsTo.modelTo) {
|
if (ref instanceof belongsTo.modelTo) {
|
||||||
var inst = self.build(data || {});
|
var inst = self.build(data || {});
|
||||||
inst[options.belongsTo](ref);
|
inst[defOpts.belongsTo](ref);
|
||||||
modelInstance.save(function(err) {
|
modelInstance.save(function(err) {
|
||||||
cb(err, err ? null : inst);
|
cb(err, err ? null : inst);
|
||||||
});
|
});
|
||||||
|
@ -2978,11 +2978,11 @@ EmbedsMany.prototype.remove = function(acInst, options, cb) {
|
||||||
var modelTo = this.definition.modelTo;
|
var modelTo = this.definition.modelTo;
|
||||||
var modelInstance = this.modelInstance;
|
var modelInstance = this.modelInstance;
|
||||||
|
|
||||||
var options = definition.options;
|
var defOpts = definition.options;
|
||||||
var belongsTo = options.belongsTo && modelTo.relations[options.belongsTo];
|
var belongsTo = defOpts.belongsTo && modelTo.relations[defOpts.belongsTo];
|
||||||
|
|
||||||
if (!belongsTo) {
|
if (!belongsTo) {
|
||||||
throw new Error('Invalid reference: ' + options.belongsTo || '(none)');
|
throw new Error('Invalid reference: ' + defOpts.belongsTo || '(none)');
|
||||||
}
|
}
|
||||||
|
|
||||||
var fk2 = belongsTo.keyTo;
|
var fk2 = belongsTo.keyTo;
|
||||||
|
|
Loading…
Reference in New Issue