| 489 | } |
| 490 | |
| 491 | function autoFetchInstance(Instance, association, opts, cb) { |
| 492 | if (!Instance.saved()) { |
| 493 | return cb(); |
| 494 | } |
| 495 | |
| 496 | if (!opts.hasOwnProperty("autoFetchLimit") || typeof opts.autoFetchLimit == "undefined") { |
| 497 | opts.autoFetchLimit = association.autoFetchLimit; |
| 498 | } |
| 499 | |
| 500 | if (opts.autoFetchLimit === 0 || (!opts.autoFetch && !association.autoFetch)) { |
| 501 | return cb(); |
| 502 | } |
| 503 | |
| 504 | Instance[association.getAccessor]({}, { autoFetchLimit: opts.autoFetchLimit - 1 }, function (err, Assoc) { |
| 505 | if (!err) { |
| 506 | // Set this way to prevent setting 'changed' status |
| 507 | Instance.__opts.associations[association.name].value = Assoc; |
| 508 | } |
| 509 | |
| 510 | return cb(); |
| 511 | }); |
| 512 | } |
| 513 | |
| 514 | function ucfirst(text) { |
| 515 | return text[0].toUpperCase() + text.substr(1).replace(/_([a-z])/, function (m, l) { |