Test instance or id by the model type
This commit is contained in:
parent
f406c32b33
commit
ee6da650e9
|
@ -737,14 +737,14 @@ HasManyThrough.prototype.add = function (acInst, done) {
|
||||||
var fk2 = findBelongsTo(modelThrough, definition.modelTo, pk2);
|
var fk2 = findBelongsTo(modelThrough, definition.modelTo, pk2);
|
||||||
|
|
||||||
query[fk1] = this.modelInstance[pk1];
|
query[fk1] = this.modelInstance[pk1];
|
||||||
query[fk2] = acInst[pk2] || acInst;
|
query[fk2] = (acInst instanceof definition.modelTo) ? acInst[pk2] : acInst;
|
||||||
|
|
||||||
var filter = { where: query };
|
var filter = { where: query };
|
||||||
|
|
||||||
definition.applyScope(this.modelInstance, filter);
|
definition.applyScope(this.modelInstance, filter);
|
||||||
|
|
||||||
data[fk1] = this.modelInstance[pk1];
|
data[fk1] = this.modelInstance[pk1];
|
||||||
data[fk2] = acInst[pk2] || acInst;
|
data[fk2] = (acInst instanceof definition.modelTo) ? acInst[pk2] : acInst;
|
||||||
definition.applyProperties(this.modelInstance, data);
|
definition.applyProperties(this.modelInstance, data);
|
||||||
|
|
||||||
// Create an instance of the through model
|
// Create an instance of the through model
|
||||||
|
@ -779,10 +779,11 @@ HasManyThrough.prototype.exists = function (acInst, done) {
|
||||||
var fk2 = findBelongsTo(modelThrough, definition.modelTo, pk2);
|
var fk2 = findBelongsTo(modelThrough, definition.modelTo, pk2);
|
||||||
|
|
||||||
query[fk1] = this.modelInstance[pk1];
|
query[fk1] = this.modelInstance[pk1];
|
||||||
query[fk2] = acInst[pk2] || acInst;
|
|
||||||
|
query[fk2] = (acInst instanceof definition.modelTo) ? acInst[pk2] : acInst;
|
||||||
|
|
||||||
data[fk1] = this.modelInstance[pk1];
|
data[fk1] = this.modelInstance[pk1];
|
||||||
data[fk2] = acInst[pk2] || acInst;
|
data[fk2] = (acInst instanceof definition.modelTo) ? acInst[pk2] : acInst;
|
||||||
|
|
||||||
modelThrough.count(query, function(err, ac) {
|
modelThrough.count(query, function(err, ac) {
|
||||||
done(err, ac > 0);
|
done(err, ac > 0);
|
||||||
|
@ -810,7 +811,7 @@ HasManyThrough.prototype.remove = function (acInst, done) {
|
||||||
var fk2 = findBelongsTo(modelThrough, definition.modelTo, pk2);
|
var fk2 = findBelongsTo(modelThrough, definition.modelTo, pk2);
|
||||||
|
|
||||||
query[fk1] = this.modelInstance[pk1];
|
query[fk1] = this.modelInstance[pk1];
|
||||||
query[fk2] = acInst[pk2] || acInst;
|
query[fk2] = (acInst instanceof definition.modelTo) ? acInst[pk2] : acInst;
|
||||||
|
|
||||||
var filter = { where: query };
|
var filter = { where: query };
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue