| 221 | } |
| 222 | |
| 223 | function autoFetchInstance(Instance, association, opts, cb) { |
| 224 | if (!Instance.saved()) { |
| 225 | return cb(); |
| 226 | } |
| 227 | |
| 228 | if (!opts.hasOwnProperty("autoFetchLimit") || !opts.autoFetchLimit) { |
| 229 | opts.autoFetchLimit = association.autoFetchLimit; |
| 230 | } |
| 231 | |
| 232 | if (opts.autoFetchLimit === 0 || (!opts.autoFetch && !association.autoFetch)) { |
| 233 | return cb(); |
| 234 | } |
| 235 | |
| 236 | if (Instance.isPersisted()) { |
| 237 | Instance[association.getAccessor]({ autoFetchLimit: opts.autoFetchLimit - 1 }, function (err, Assoc) { |
| 238 | if (!err) { |
| 239 | Instance[association.name] = Assoc; |
| 240 | } |
| 241 | |
| 242 | return cb(); |
| 243 | }); |
| 244 | } else { |
| 245 | return cb(); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | function ucfirst(text) { |
| 250 | return text[0].toUpperCase() + text.substr(1); |