Skip to content

Commit 19ee31e

Browse files
committed
Changes autoFetch to avoid autofetching if instance is not saved (it's new!) (#242)
1 parent d2d44d8 commit 19ee31e

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

lib/Associations/Extend.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ function extendInstance(Model, Instance, Driver, association, opts) {
159159
}
160160

161161
function autoFetchInstance(Instance, association, opts, cb) {
162+
if (!Instance.saved()) {
163+
return cb();
164+
}
165+
162166
if (!opts.hasOwnProperty("autoFetchLimit") || typeof opts.autoFetchLimit == "undefined") {
163167
opts.autoFetchLimit = association.autoFetchLimit;
164168
}

lib/Associations/Many.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ function extendInstance(Model, Instance, Driver, association, opts, createInstan
388388
}
389389

390390
function autoFetchInstance(Instance, association, opts, cb) {
391+
if (!Instance.saved()) {
392+
return cb();
393+
}
394+
391395
if (!opts.hasOwnProperty("autoFetchLimit") || typeof opts.autoFetchLimit == "undefined") {
392396
opts.autoFetchLimit = association.autoFetchLimit;
393397
}

lib/Associations/One.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ function extendInstance(Model, Instance, Driver, association, opts) {
223223
}
224224

225225
function autoFetchInstance(Instance, association, opts, cb) {
226+
if (!Instance.saved()) {
227+
return cb();
228+
}
229+
226230
if (!opts.hasOwnProperty("autoFetchLimit") || typeof opts.autoFetchLimit == "undefined") {
227231
opts.autoFetchLimit = association.autoFetchLimit;
228232
}

0 commit comments

Comments
 (0)