Skip to content

Commit 7983efd

Browse files
committed
Fixes autoFetchLimit and cascadeRemove options not being used when set to 0 or false (fixes #144)
1 parent 15e63eb commit 7983efd

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

lib/Model.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ function Model(opts) {
158158
conditions[opts.keys[i]] = ids[i];
159159
}
160160

161+
if (!options.hasOwnProperty("autoFetchLimit")) {
162+
options.autoFetchLimit = opts.autoFetchLimit;
163+
}
164+
if (!options.hasOwnProperty("cascadeRemove")) {
165+
options.cascadeRemove = opts.cascadeRemove;
166+
}
167+
161168
opts.driver.find(model_fields, opts.table, conditions, { limit: 1 }, function (err, data) {
162169
if (err) {
163170
return cb(err);
@@ -172,8 +179,8 @@ function Model(opts) {
172179
return createInstance(data[0], {
173180
autoSave : opts.autoSave,
174181
autoFetch : (options.autoFetchLimit === 0 ? false : opts.autoFetch),
175-
autoFetchLimit : options.autoFetchLimit || opts.autoFetchLimit,
176-
cascadeRemove : options.cascadeRemove || opts.cascadeRemove
182+
autoFetchLimit : options.autoFetchLimit,
183+
cascadeRemove : options.cascadeRemove
177184
}, cb);
178185
}, function (instance) {
179186
return cb(null, instance);
@@ -237,6 +244,12 @@ function Model(opts) {
237244
if (!options.hasOwnProperty("cache")) {
238245
options.cache = opts.cache;
239246
}
247+
if (!options.hasOwnProperty("autoFetchLimit")) {
248+
options.autoFetchLimit = opts.autoFetchLimit;
249+
}
250+
if (!options.hasOwnProperty("cascadeRemove")) {
251+
options.cascadeRemove = opts.cascadeRemove;
252+
}
240253

241254
if (order) {
242255
order = Utilities.standardizeOrder(order);
@@ -261,8 +274,8 @@ function Model(opts) {
261274
return createInstance(data, {
262275
autoSave : opts.autoSave,
263276
autoFetch : (options.autoFetchLimit === 0 ? false : (options.autoFetch || opts.autoFetch)),
264-
autoFetchLimit : options.autoFetchLimit || opts.autoFetchLimit,
265-
cascadeRemove : options.cascadeRemove || opts.cascadeRemove,
277+
autoFetchLimit : options.autoFetchLimit,
278+
cascadeRemove : options.cascadeRemove,
266279
extra : options.extra,
267280
extra_info : options.extra_info
268281
}, cb);

0 commit comments

Comments
 (0)