Test instance or id by the model type

This commit is contained in:
Raymond Feng 2014-07-15 16:09:54 -07:00
parent f406c32b33
commit ee6da650e9
1 changed files with 6 additions and 5 deletions

View File

@ -737,14 +737,14 @@ HasManyThrough.prototype.add = function (acInst, done) {
var fk2 = findBelongsTo(modelThrough, definition.modelTo, pk2);
query[fk1] = this.modelInstance[pk1];
query[fk2] = acInst[pk2] || acInst;
query[fk2] = (acInst instanceof definition.modelTo) ? acInst[pk2] : acInst;
var filter = { where: query };
definition.applyScope(this.modelInstance, filter);
data[fk1] = this.modelInstance[pk1];
data[fk2] = acInst[pk2] || acInst;
data[fk2] = (acInst instanceof definition.modelTo) ? acInst[pk2] : acInst;
definition.applyProperties(this.modelInstance, data);
// Create an instance of the through model
@ -779,10 +779,11 @@ HasManyThrough.prototype.exists = function (acInst, done) {
var fk2 = findBelongsTo(modelThrough, definition.modelTo, pk2);
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[fk2] = acInst[pk2] || acInst;
data[fk2] = (acInst instanceof definition.modelTo) ? acInst[pk2] : acInst;
modelThrough.count(query, function(err, ac) {
done(err, ac > 0);
@ -810,7 +811,7 @@ HasManyThrough.prototype.remove = function (acInst, done) {
var fk2 = findBelongsTo(modelThrough, definition.modelTo, pk2);
query[fk1] = this.modelInstance[pk1];
query[fk2] = acInst[pk2] || acInst;
query[fk2] = (acInst instanceof definition.modelTo) ? acInst[pk2] : acInst;
var filter = { where: query };