Merge pull request #443 from clarkorz/fix/findOrCreate-ThroughModel
Always use findOrCreate when creating a through model
This commit is contained in:
commit
5e0451eef0
|
@ -954,13 +954,14 @@ HasManyThrough.prototype.create = function create(data, done) {
|
|||
var fk2 = keys[1];
|
||||
|
||||
function createRelation(to, next) {
|
||||
var d = {};
|
||||
d[fk1] = modelInstance[definition.keyFrom];
|
||||
d[fk2] = to[pk2];
|
||||
var d = {}, q = {}, filter = {where:q};
|
||||
d[fk1] = q[fk1] = modelInstance[definition.keyFrom];
|
||||
d[fk2] = q[fk2] = to[pk2];
|
||||
definition.applyProperties(modelInstance, d);
|
||||
definition.applyScope(modelInstance, filter);
|
||||
|
||||
// Then create the through model
|
||||
modelThrough.create(d, function (e, through) {
|
||||
modelThrough.findOrCreate(filter, d, function (e, through) {
|
||||
if (e) {
|
||||
// Undo creation of the target model
|
||||
to.destroy(function () {
|
||||
|
|
Loading…
Reference in New Issue