(opts)
| 25 | exports.Model = Model; |
| 26 | |
| 27 | function Model(opts) { |
| 28 | opts = _.defaults(opts || {}, { |
| 29 | keys: [] |
| 30 | }); |
| 31 | opts.keys = Array.isArray(opts.keys) ? opts.keys : [opts.keys]; |
| 32 | |
| 33 | var one_associations = []; |
| 34 | var many_associations = []; |
| 35 | var extend_associations = []; |
| 36 | var association_properties = []; |
| 37 | var model_fields = []; |
| 38 | var fieldToPropertyMap = {}; |
| 39 | var allProperties = {}; |
| 40 | var keyProperties = []; |
| 41 | |
| 42 | var createHookHelper = function (hook) { |
| 43 | return function (cb) { |
| 44 | if (typeof cb !== "function") { |
| 45 | delete opts.hooks[hook]; |
| 46 | } else { |
| 47 | opts.hooks[hook] = cb; |
| 48 | } |
| 49 | return this; |
| 50 | }; |
| 51 | }; |
| 52 | |
| 53 | var createInstance = function (data, inst_opts, cb) { |
| 54 | if (!inst_opts) { |
| 55 | inst_opts = {}; |
| 56 | } |
| 57 | |
| 58 | var found_assoc = false, i, k; |
| 59 | |
| 60 | for (k in data) { |
| 61 | if (k === "extra_field") continue; |
| 62 | if (opts.properties.hasOwnProperty(k)) continue; |
| 63 | if (inst_opts.extra && inst_opts.extra.hasOwnProperty(k)) continue; |
| 64 | if (opts.keys.indexOf(k) >= 0) continue; |
| 65 | if (association_properties.indexOf(k) >= 0) continue; |
| 66 | |
| 67 | for (i = 0; i < one_associations.length; i++) { |
| 68 | if (one_associations[i].name === k) { |
| 69 | found_assoc = true; |
| 70 | break; |
| 71 | } |
| 72 | } |
| 73 | if (!found_assoc) { |
| 74 | for (i = 0; i < many_associations.length; i++) { |
| 75 | if (many_associations[i].name === k) { |
| 76 | found_assoc = true; |
| 77 | break; |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | if (!found_assoc) { |
| 82 | delete data[k]; |
| 83 | } |
| 84 | } |
nothing calls this directly
no test coverage detected