BVB Source Codes

waterline Show help-replace-collection.js Source code

Return Download waterline: download help-replace-collection.js Source code - Download waterline Source code - Type:.js
  1. /**
  2.  * Module dependencies
  3.  */
  4.  
  5. var assert = require('assert');
  6. var _ = require('@sailshq/lodash');
  7. var async = require('async');
  8.  
  9.  
  10.  
  11. /**
  12.  * helpReplaceCollection()
  13.  *
  14.  * @param  {Dictionary}   query  [stage 2 query]
  15.  * @param  {Ref}   orm
  16.  * @param  {Function} done
  17.  */
  18.  
  19. module.exports = function helpReplaceCollection(query, orm, cb) {
  20.  
  21.   // Validate arguments
  22.   if (_.isUndefined(query) || !_.isObject(query)) {
  23.     throw new Error('Consistency violation: Invalid arguments - missing or invalid `query` argument (a stage 2 query).');
  24.   }
  25.  
  26.   if (_.isUndefined(orm) || !_.isObject(orm)) {
  27.     throw new Error('Consistency violation: Invalid arguments - missing or invalid `orm` argument.');
  28.   }
  29.  
  30.   // Get the model being used as the parent
  31.   var WLModel = orm.collections[query.using];
  32.   try { assert.equal(query.using.toLowerCase(), query.using, '`query.using` (identity) should have already been normalized before getting here!  But it was not: '+query.using); } catch (e) { return cb(e); }
  33.  
  34.   // Look up the association by name in the schema definition.
  35.   var schemaDef = WLModel.schema[query.collectionAttrName];
  36.  
  37.   // Look up the associated collection using the schema def which should have
  38.   // join tables normalized
  39.   var WLChild = orm.collections[schemaDef.collection];
  40.   try {
  41.     assert.equal(schemaDef.collection.toLowerCase(), schemaDef.collection, '`schemaDef.collection` (identity) should have already been normalized before getting here!  But it was not: '+schemaDef.collection);
  42.     assert.equal(schemaDef.referenceIdentity.toLowerCase(), schemaDef.referenceIdentity, '`schemaDef.referenceIdentity` (identity) should have already been normalized before getting here!  But it was not: '+schemaDef.referenceIdentity);
  43.     assert.equal(Object.getPrototypeOf(WLChild).identity.toLowerCase(), Object.getPrototypeOf(WLChild).identity, '`Object.getPrototypeOf(WLChild).identity` (identity) should have already been normalized before getting here!  But it was not: '+Object.getPrototypeOf(WLChild).identity);
  44.   } catch (e) { return cb(e); }
  45.  
  46.   // Flag to determine if the WLChild is a manyToMany relation
  47.   var manyToMany = false;
  48.  
  49.   // Check if the schema references something other than the WLChild
  50.   if (schemaDef.referenceIdentity !== Object.getPrototypeOf(WLChild).identity) {
  51.     manyToMany = true;
  52.     WLChild = orm.collections[schemaDef.referenceIdentity];
  53.   }
  54.  
  55.   // Check if the child is a join table
  56.   if (_.has(Object.getPrototypeOf(WLChild), 'junctionTable') && WLChild.junctionTable) {
  57.     manyToMany = true;
  58.   }
  59.  
  60.   // Check if the child is a through table
  61.   if (_.has(Object.getPrototypeOf(WLChild), 'throughTable') && _.keys(WLChild.throughTable).length) {
  62.     manyToMany = true;
  63.   }
  64.  
  65.  
  66.   // Ensure the query skips lifecycle callbacks
  67.   query.meta = query.meta || {};
  68.   query.meta.skipAllLifecycleCallbacks = true;
  69.  
  70.  
  71.  
  72.   //   鈻堚枅鈺椻枅鈻堚枅鈺   鈻堚枅鈺      鈻堚枅鈻堚晽   鈻堚枅鈻堚晽鈻堚枅鈺
  73.   //  鈻堚枅鈺斺暆鈻堚枅鈻堚枅鈺  鈻堚枅鈺      鈻堚枅鈻堚枅鈺 鈻堚枅鈻堚枅鈺戔暁鈻堚枅鈺
  74.   //  鈻堚枅鈺 鈻堚枅鈺斺枅鈻堚晽 鈻堚枅鈺      鈻堚枅鈺斺枅鈻堚枅鈻堚晹鈻堚枅鈺 鈻堚枅鈺
  75.   //  鈻堚枅鈺 鈻堚枅鈺戔暁鈻堚枅鈺椻枅鈻堚晳      鈻堚枅鈺戔暁鈻堚枅鈺斺暆鈻堚枅鈺 鈻堚枅鈺
  76.   //  鈺氣枅鈻堚晽鈻堚枅鈺 鈺氣枅鈻堚枅鈻堚晳鈻堚枅鈺椻枅鈻堚晽鈻堚枅鈺 鈺氣晲鈺 鈻堚枅鈺戔枅鈻堚晹鈺
  77.   //   鈺氣晲鈺濃暁鈺愨暆  鈺氣晲鈺愨晲鈺濃暁鈺愨暆鈺氣晲鈺濃暁鈺愨暆     鈺氣晲鈺濃暁鈺愨暆
  78.   //
  79.   //  鈻堚枅鈻堚晽   鈻堚枅鈻堚晽 鈻堚枅鈻堚枅鈻堚晽 鈻堚枅鈻堚晽   鈻堚枅鈺椻枅鈻堚晽   鈻堚枅鈺    鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈺 鈻堚枅鈻堚枅鈻堚枅鈺     鈻堚枅鈻堚晽   鈻堚枅鈻堚晽 鈻堚枅鈻堚枅鈻堚晽 鈻堚枅鈻堚晽   鈻堚枅鈺椻枅鈻堚晽   鈻堚枅鈺
  80.   //  鈻堚枅鈻堚枅鈺 鈻堚枅鈻堚枅鈺戔枅鈻堚晹鈺愨晲鈻堚枅鈺椻枅鈻堚枅鈻堚晽  鈻堚枅鈺戔暁鈻堚枅鈺 鈻堚枅鈺斺暆    鈺氣晲鈺愨枅鈻堚晹鈺愨晲鈺濃枅鈻堚晹鈺愨晲鈺愨枅鈻堚晽    鈻堚枅鈻堚枅鈺 鈻堚枅鈻堚枅鈺戔枅鈻堚晹鈺愨晲鈻堚枅鈺椻枅鈻堚枅鈻堚晽  鈻堚枅鈺戔暁鈻堚枅鈺 鈻堚枅鈺斺暆
  81.   //  鈻堚枅鈺斺枅鈻堚枅鈻堚晹鈻堚枅鈺戔枅鈻堚枅鈻堚枅鈻堚枅鈺戔枅鈻堚晹鈻堚枅鈺 鈻堚枅鈺 鈺氣枅鈻堚枅鈻堚晹鈺        鈻堚枅鈺   鈻堚枅鈺   鈻堚枅鈺    鈻堚枅鈺斺枅鈻堚枅鈻堚晹鈻堚枅鈺戔枅鈻堚枅鈻堚枅鈻堚枅鈺戔枅鈻堚晹鈻堚枅鈺 鈻堚枅鈺 鈺氣枅鈻堚枅鈻堚晹鈺
  82.   //  鈻堚枅鈺戔暁鈻堚枅鈺斺暆鈻堚枅鈺戔枅鈻堚晹鈺愨晲鈻堚枅鈺戔枅鈻堚晳鈺氣枅鈻堚晽鈻堚枅鈺  鈺氣枅鈻堚晹鈺         鈻堚枅鈺   鈻堚枅鈺   鈻堚枅鈺    鈻堚枅鈺戔暁鈻堚枅鈺斺暆鈻堚枅鈺戔枅鈻堚晹鈺愨晲鈻堚枅鈺戔枅鈻堚晳鈺氣枅鈻堚晽鈻堚枅鈺  鈺氣枅鈻堚晹鈺
  83.   //  鈻堚枅鈺 鈺氣晲鈺 鈻堚枅鈺戔枅鈻堚晳  鈻堚枅鈺戔枅鈻堚晳 鈺氣枅鈻堚枅鈻堚晳   鈻堚枅鈺          鈻堚枅鈺   鈺氣枅鈻堚枅鈻堚枅鈻堚晹鈺    鈻堚枅鈺 鈺氣晲鈺 鈻堚枅鈺戔枅鈻堚晳  鈻堚枅鈺戔枅鈻堚晳 鈺氣枅鈻堚枅鈻堚晳   鈻堚枅鈺
  84.   //  鈺氣晲鈺     鈺氣晲鈺濃暁鈺愨暆  鈺氣晲鈺濃暁鈺愨暆  鈺氣晲鈺愨晲鈺   鈺氣晲鈺          鈺氣晲鈺    鈺氣晲鈺愨晲鈺愨晲鈺     鈺氣晲鈺     鈺氣晲鈺濃暁鈺愨暆  鈺氣晲鈺濃暁鈺愨暆  鈺氣晲鈺愨晲鈺   鈺氣晲鈺
  85.   //
  86.   // If the collection uses a join table, build a query that removes the records
  87.   // from the table.
  88.   if (manyToMany) {
  89.  
  90.     //  鈺斺晽 鈺 鈺︹暒鈺  鈺斺暒鈺  鈹攢鈹愨攲鈹€鈹愨攲鈹€鈹愨攲鈹€鈹愨敩鈹€鈹愨攲鈹€鈹愨攲鈹愨攲鈹屸攢鈹愨攲鈹€鈹  鈹屸敩鈹愨攲鈹€鈹愨攲鈹€鈹愨攲鈹€鈹愨敩鈹屸攼鈹屸攲鈹€鈹
  91.     //  鈺犫暕鈺椻晳 鈺戔晳鈺   鈺戔晳  鈹溾敩鈹樷敎鈹 鈹溾敜 鈹溾敜 鈹溾敩鈹樷敎鈹 鈹傗攤鈹傗攤  鈹溾敜   鈹傗攤鈹傗敎鈹€鈹も敎鈹€鈹樷敎鈹€鈹樷攤鈹傗攤鈹傗攤 鈹
  92.     //  鈺氣晲鈺濃暁鈺愨暆鈺┾暕鈺愨暆鈺愨暕鈺  鈹粹敂鈹€鈹斺攢鈹樷敂  鈹斺攢鈹樷敶鈹斺攢鈹斺攢鈹樷敇鈹斺敇鈹斺攢鈹樷敂鈹€鈹  鈹 鈹粹敶 鈹粹敶  鈹  鈹粹敇鈹斺敇鈹斺攢鈹
  93.     //
  94.     // Maps out the parent and child attribute names to use for the query.
  95.     var parentReference;
  96.     var childReference;
  97.  
  98.     // Find the parent reference
  99.     if (_.has(Object.getPrototypeOf(WLChild), 'junctionTable') && WLChild.junctionTable) {
  100.       // Assumes the generated junction table will only ever have two foreign key
  101.       // values. Should be safe for now and any changes would need to be made in
  102.       // Waterline-Schema where a map could be formed anyway.
  103.       _.each(WLChild.schema, function(val, key) {
  104.         if (!_.has(val, 'references')) {
  105.           return;
  106.         }
  107.  
  108.         // If this is the piece of the join table, set the parent reference.
  109.         if (_.has(val, 'columnName') && val.columnName === schemaDef.on) {
  110.           parentReference = key;
  111.         }
  112.       });
  113.     }
  114.     // If it's a through table, grab the parent and child reference from the
  115.     // through table mapping that was generated by Waterline-Schema.
  116.     else if (_.has(Object.getPrototypeOf(WLChild), 'throughTable')) {
  117.       childReference = WLChild.throughTable[WLModel.identity + '.' + query.collectionAttrName];
  118.       _.each(WLChild.throughTable, function(val, key) {
  119.         if (key !== WLModel.identity + '.' + query.collectionAttrName) {
  120.           parentReference = val;
  121.         }
  122.       });
  123.     }//>-
  124.  
  125.  
  126.  
  127.     // Find the child reference in a junction table
  128.     if (_.has(Object.getPrototypeOf(WLChild), 'junctionTable') && WLChild.junctionTable) {
  129.       // Assumes the generated junction table will only ever have two foreign key
  130.       // values. Should be safe for now and any changes would need to be made in
  131.       // Waterline-Schema where a map could be formed anyway.
  132.       _.each(WLChild.schema, function(val, key) {
  133.         if (!_.has(val, 'references')) {
  134.           return;
  135.         }
  136.  
  137.         // If this is the other piece of the join table, set the child reference.
  138.         if (_.has(val, 'columnName') && val.columnName !== schemaDef.on) {
  139.           childReference = key;
  140.         }
  141.       });
  142.     }
  143.  
  144.  
  145.     //  鈺斺晽 鈺 鈺︹暒鈺  鈺斺暒鈺  鈹屸敩鈹愨攲鈹€鈹愨攲鈹€鈹愨攲鈹攼鈹攢鈹愨攲鈹€鈹愨敩 鈹  鈹屸攢鈹 鈹 鈹攲鈹€鈹愨敩鈹€鈹愨敩 鈹
  146.     //  鈺犫暕鈺椻晳 鈺戔晳鈺   鈺戔晳   鈹傗攤鈹溾敜 鈹斺攢鈹 鈹 鈹溾敩鈹樷攤 鈹傗敂鈹敇  鈹傗攢鈹尖攼鈹 鈹傗敎鈹 鈹溾敩鈹樷敂鈹敇
  147.     //  鈺氣晲鈺濃暁鈺愨暆鈺┾暕鈺愨暆鈺愨暕鈺  鈹€鈹粹敇鈹斺攢鈹樷敂鈹€鈹 鈹 鈹粹敂鈹€鈹斺攢鈹 鈹   鈹斺攢鈹樷敂鈹斺攢鈹樷敂鈹€鈹樷敶鈹斺攢 鈹
  148.     //
  149.     // When replacing a collection, the first step is to remove all the records
  150.     // for the target id's in the join table.
  151.     var destroyQuery = {};
  152.     destroyQuery[parentReference] = query.targetRecordIds;
  153.  
  154.     //  鈺斺晽 鈺 鈺︹暒鈺  鈺斺暒鈺  鈹攲鈹愨攲鈹屸攢鈹愨攲鈹€鈹愨敩鈹€鈹愨攲鈹攼  鈹屸攢鈹 鈹 鈹攲鈹€鈹愨敩鈹€鈹愨敩 鈹
  155.     //  鈺犫暕鈺椻晳 鈺戔晳鈺   鈺戔晳  鈹傗攤鈹傗攤鈹斺攢鈹愨敎鈹 鈹溾敩鈹 鈹   鈹傗攢鈹尖攼鈹 鈹傗敎鈹 鈹溾敩鈹樷敂鈹敇
  156.     //  鈺氣晲鈺濃暁鈺愨暆鈺┾暕鈺愨暆鈺愨暕鈺  鈹粹敇鈹斺敇鈹斺攢鈹樷敂鈹€鈹樷敶鈹斺攢 鈹   鈹斺攢鈹樷敂鈹斺攢鈹樷敂鈹€鈹樷敶鈹斺攢 鈹
  157.     //
  158.     // Then build up an insert query for creating the new join table records.
  159.     var insertRecords = [];
  160.  
  161.     // For each target record, build an insert query for the associated records.
  162.     _.each(query.targetRecordIds, function(targetId) {
  163.       _.each(query.associatedIds, function(associatedId) {
  164.         var record = {};
  165.         record[parentReference] = targetId;
  166.         record[childReference] = associatedId;
  167.         insertRecords.push(record);
  168.       });
  169.     });
  170.  
  171.  
  172.     //  鈺︹晲鈺椻暒 鈺︹晹鈺椻晹  鈹屸敩鈹愨攲鈹€鈹愨攲鈹€鈹愨攲鈹攼鈹攢鈹愨攲鈹€鈹愨敩 鈹  鈹屸攢鈹 鈹 鈹攲鈹€鈹愨敩鈹€鈹愨敩 鈹
  173.     //  鈺犫暒鈺濃晳 鈺戔晳鈺戔晳   鈹傗攤鈹溾敜 鈹斺攢鈹 鈹 鈹溾敩鈹樷攤 鈹傗敂鈹敇  鈹傗攢鈹尖攼鈹 鈹傗敎鈹 鈹溾敩鈹樷敂鈹敇
  174.     //  鈺┾暁鈺愨暁鈺愨暆鈺濃暁鈺  鈹€鈹粹敇鈹斺攢鈹樷敂鈹€鈹 鈹 鈹粹敂鈹€鈹斺攢鈹 鈹   鈹斺攢鈹樷敂鈹斺攢鈹樷敂鈹€鈹樷敶鈹斺攢 鈹
  175.     WLChild.destroy(destroyQuery, function destroyCb(err) {
  176.       if (err) {
  177.         return cb(err);
  178.       }
  179.  
  180.       // If there were no associated id's to insert, exit out
  181.       if (!query.associatedIds.length) {
  182.         return cb();
  183.       }
  184.  
  185.       //  鈺︹晲鈺椻暒 鈺︹晹鈺椻晹  鈹屸攢鈹愨敩鈹€鈹愨攲鈹€鈹愨攲鈹€鈹愨攲鈹攼鈹屸攢鈹  鈹屸攢鈹 鈹 鈹攲鈹€鈹愨敩鈹€鈹愨敩 鈹
  186.       //  鈺犫暒鈺濃晳 鈺戔晳鈺戔晳  鈹  鈹溾敩鈹樷敎鈹 鈹溾攢鈹 鈹 鈹溾敜   鈹傗攢鈹尖攼鈹 鈹傗敎鈹 鈹溾敩鈹樷敂鈹敇
  187.       //  鈺┾暁鈺愨暁鈺愨暆鈺濃暁鈺  鈹斺攢鈹樷敶鈹斺攢鈹斺攢鈹樷敶 鈹 鈹 鈹斺攢鈹  鈹斺攢鈹樷敂鈹斺攢鈹樷敂鈹€鈹樷敶鈹斺攢 鈹
  188.       WLChild.createEach(insertRecords, cb, query.meta);
  189.     }, query.meta);
  190.  
  191.     return;
  192.   }//-鈥
  193.  
  194.  
  195.   //   鈻堚枅鈺椻枅鈻堚枅鈺   鈻堚枅鈺      鈻堚枅鈺椻枅鈻堚晽
  196.   //  鈻堚枅鈺斺暆鈻堚枅鈻堚枅鈺  鈻堚枅鈺     鈻堚枅鈻堚晳鈺氣枅鈻堚晽
  197.   //  鈻堚枅鈺 鈻堚枅鈺斺枅鈻堚晽 鈻堚枅鈺     鈺氣枅鈻堚晳 鈻堚枅鈺
  198.   //  鈻堚枅鈺 鈻堚枅鈺戔暁鈻堚枅鈺椻枅鈻堚晳      鈻堚枅鈺 鈻堚枅鈺
  199.   //  鈺氣枅鈻堚晽鈻堚枅鈺 鈺氣枅鈻堚枅鈻堚晳鈻堚枅鈺椻枅鈻堚晽鈻堚枅鈺戔枅鈻堚晹鈺
  200.   //   鈺氣晲鈺濃暁鈺愨暆  鈺氣晲鈺愨晲鈺濃暁鈺愨暆鈺氣晲鈺濃暁鈺愨暆鈺氣晲鈺
  201.   //
  202.   //  鈻堚枅鈻堚枅鈻堚枅鈺 鈻堚枅鈻堚枅鈻堚枅鈻堚晽鈻堚枅鈺      鈻堚枅鈻堚枅鈻堚枅鈺 鈻堚枅鈻堚晽   鈻堚枅鈺 鈻堚枅鈻堚枅鈻堚枅鈺 鈻堚枅鈻堚枅鈻堚枅鈻堚晽    鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈺 鈻堚枅鈻堚枅鈻堚枅鈺
  203.   //  鈻堚枅鈺斺晲鈺愨枅鈻堚晽鈻堚枅鈺斺晲鈺愨晲鈺愨暆鈻堚枅鈺     鈻堚枅鈺斺晲鈺愨晲鈻堚枅鈺椻枅鈻堚枅鈻堚晽  鈻堚枅鈺戔枅鈻堚晹鈺愨晲鈺愨晲鈺 鈻堚枅鈺斺晲鈺愨晲鈺愨暆    鈺氣晲鈺愨枅鈻堚晹鈺愨晲鈺濃枅鈻堚晹鈺愨晲鈺愨枅鈻堚晽
  204.   //  鈻堚枅鈻堚枅鈻堚枅鈺斺暆鈻堚枅鈻堚枅鈻堚晽  鈻堚枅鈺     鈻堚枅鈺   鈻堚枅鈺戔枅鈻堚晹鈻堚枅鈺 鈻堚枅鈺戔枅鈻堚晳  鈻堚枅鈻堚晽鈻堚枅鈻堚枅鈻堚枅鈻堚晽       鈻堚枅鈺   鈻堚枅鈺   鈻堚枅鈺
  205.   //  鈻堚枅鈺斺晲鈺愨枅鈻堚晽鈻堚枅鈺斺晲鈺愨暆  鈻堚枅鈺     鈻堚枅鈺   鈻堚枅鈺戔枅鈻堚晳鈺氣枅鈻堚晽鈻堚枅鈺戔枅鈻堚晳   鈻堚枅鈺戔暁鈺愨晲鈺愨晲鈻堚枅鈺       鈻堚枅鈺   鈻堚枅鈺   鈻堚枅鈺
  206.   //  鈻堚枅鈻堚枅鈻堚枅鈺斺暆鈻堚枅鈻堚枅鈻堚枅鈻堚晽鈻堚枅鈻堚枅鈻堚枅鈻堚晽鈺氣枅鈻堚枅鈻堚枅鈻堚晹鈺濃枅鈻堚晳 鈺氣枅鈻堚枅鈻堚晳鈺氣枅鈻堚枅鈻堚枅鈻堚晹鈺濃枅鈻堚枅鈻堚枅鈻堚枅鈺       鈻堚枅鈺   鈺氣枅鈻堚枅鈻堚枅鈻堚晹鈺
  207.   //  鈺氣晲鈺愨晲鈺愨晲鈺 鈺氣晲鈺愨晲鈺愨晲鈺愨暆鈺氣晲鈺愨晲鈺愨晲鈺愨暆 鈺氣晲鈺愨晲鈺愨晲鈺 鈺氣晲鈺  鈺氣晲鈺愨晲鈺 鈺氣晲鈺愨晲鈺愨晲鈺 鈺氣晲鈺愨晲鈺愨晲鈺愨暆       鈺氣晲鈺    鈺氣晲鈺愨晲鈺愨晲鈺
  208.   //
  209.   // Otherwise the child records need to be updated to reflect the nulled out
  210.   // foreign key value and then updated to reflect the new association.
  211.  
  212.  
  213.   //  鈺斺晽 鈺 鈺︹暒鈺  鈺斺暒鈺  鈹屸攼鈹屸敩 鈹敩  鈹    鈹屸攢鈹愨敩 鈹攲鈹攼  鈹屸攢鈹 鈹 鈹攲鈹€鈹愨敩鈹€鈹愨敩 鈹
  214.   //  鈺犫暕鈺椻晳 鈺戔晳鈺   鈺戔晳  鈹傗攤鈹傗攤 鈹傗攤  鈹    鈹 鈹傗攤 鈹 鈹   鈹傗攢鈹尖攼鈹 鈹傗敎鈹 鈹溾敩鈹樷敂鈹敇
  215.   //  鈺氣晲鈺濃暁鈺愨暆鈺┾暕鈺愨暆鈺愨暕鈺  鈹樷敂鈹樷敂鈹€鈹樷敶鈹€鈹樷敶鈹€鈹  鈹斺攢鈹樷敂鈹€鈹 鈹   鈹斺攢鈹樷敂鈹斺攢鈹樷敂鈹€鈹樷敶鈹斺攢 鈹
  216.  
  217.   // Build up a search criteria
  218.   var nullOutCriteria = {
  219.     where: {}
  220.   };
  221.  
  222.   nullOutCriteria.where[schemaDef.via] = query.targetRecordIds;
  223.  
  224.   // Build up the values to update
  225.   var valuesToUpdate = {};
  226.   valuesToUpdate[schemaDef.via] = null;
  227.  
  228.  
  229.   //  鈺斺晽 鈺 鈺︹暒鈺  鈺斺暒鈺  鈹 鈹攲鈹€鈹愨攲鈹攼鈹屸攢鈹愨攲鈹攼鈹屸攢鈹  鈹屸攢鈹 鈹 鈹攲鈹€鈹愨敩鈹€鈹愨敩 鈹
  230.   //  鈺犫暕鈺椻晳 鈺戔晳鈺   鈺戔晳  鈹 鈹傗敎鈹€鈹 鈹傗攤鈹溾攢鈹 鈹 鈹溾敜   鈹傗攢鈹尖攼鈹 鈹傗敎鈹 鈹溾敩鈹樷敂鈹敇
  231.   //  鈺氣晲鈺濃暁鈺愨暆鈺┾暕鈺愨暆鈺愨暕鈺  鈹斺攢鈹樷敶  鈹€鈹粹敇鈹 鈹 鈹 鈹斺攢鈹  鈹斺攢鈹樷敂鈹斺攢鈹樷敂鈹€鈹樷敶鈹斺攢 鈹
  232.  
  233.   var updateQueries = [];
  234.  
  235.   // For each target record, build an update query for the associated records.
  236.   _.each(query.targetRecordIds, function(targetId) {
  237.     _.each(query.associatedIds, function(associatedId) {
  238.       // Build up a search criteria
  239.       var criteria = {
  240.         where: {}
  241.       };
  242.  
  243.       criteria.where[WLChild.primaryKey] = associatedId;
  244.  
  245.       // Build up the update values
  246.       var valuesToUpdate = {};
  247.       valuesToUpdate[schemaDef.via] = targetId;
  248.  
  249.       updateQueries.push({
  250.         criteria: criteria,
  251.         valuesToUpdate: valuesToUpdate
  252.       });
  253.     });
  254.   });
  255.  
  256.  
  257.   //  鈺︹晲鈺椻暒 鈺︹晹鈺椻晹  鈹屸攼鈹屸敩 鈹敩  鈹    鈹屸攢鈹愨敩 鈹攲鈹攼  鈹屸攢鈹 鈹 鈹攲鈹€鈹愨敩鈹€鈹愨敩 鈹
  258.   //  鈺犫暒鈺濃晳 鈺戔晳鈺戔晳  鈹傗攤鈹傗攤 鈹傗攤  鈹    鈹 鈹傗攤 鈹 鈹   鈹傗攢鈹尖攼鈹 鈹傗敎鈹 鈹溾敩鈹樷敂鈹敇
  259.   //  鈺┾暁鈺愨暁鈺愨暆鈺濃暁鈺  鈹樷敂鈹樷敂鈹€鈹樷敶鈹€鈹樷敶鈹€鈹  鈹斺攢鈹樷敂鈹€鈹 鈹   鈹斺攢鈹樷敂鈹斺攢鈹樷敂鈹€鈹樷敶鈹斺攢 鈹
  260.   WLChild.update(nullOutCriteria, valuesToUpdate, function(err) {
  261.     if (err) {
  262.       return cb(err);
  263.     }
  264.  
  265.     //  鈺︹晲鈺椻暒 鈺︹晹鈺椻晹  鈹 鈹攲鈹€鈹愨攲鈹攼鈹屸攢鈹愨攲鈹攼鈹屸攢鈹  鈹屸攢鈹 鈹 鈹攲鈹€鈹愨敩鈹€鈹愨敩鈹屸攢鈹愨攲鈹€鈹
  266.     //  鈺犫暒鈺濃晳 鈺戔晳鈺戔晳  鈹 鈹傗敎鈹€鈹 鈹傗攤鈹溾攢鈹 鈹 鈹溾敜   鈹傗攢鈹尖攼鈹 鈹傗敎鈹 鈹溾敩鈹樷攤鈹溾敜 鈹斺攢鈹
  267.     //  鈺┾暁鈺愨暁鈺愨暆鈺濃暁鈺  鈹斺攢鈹樷敶  鈹€鈹粹敇鈹 鈹 鈹 鈹斺攢鈹  鈹斺攢鈹樷敂鈹斺攢鈹樷敂鈹€鈹樷敶鈹斺攢鈹粹敂鈹€鈹樷敂鈹€鈹
  268.     async.each(updateQueries, function(query, next) {
  269.  
  270.       WLChild.update(query.criteria, query.valuesToUpdate, next, query.meta);
  271.  
  272.     },// ~鈭?掳
  273.     function _after(err) {
  274.       if (err) {
  275.         return cb(err);
  276.       }
  277.  
  278.       return cb();
  279.  
  280.     });
  281.   }, query.meta);
  282. };
  283.  
downloadhelp-replace-collection.js Source code - Download waterline Source code
Related Source Codes/Software:
notepad-plus-plus - Notepad++ official repository h... 2017-01-10
che - Eclipse Che: Next-generation Eclipse IDE. Open sou... 2017-01-10
Gource - oftware version control visualization ... 2017-01-10
FDFullscreenPopGesture - A UINavigationController's category to enable full... 2017-01-10
node-style-guide - A guide for styling your node.js / JavaScript code... 2017-01-09
Workerman - An asynchronous event driven PHP framework for eas... 2017-01-10
structor - An advanced visual editor for React components ... 2017-01-10
golearn - Machine Learning for Go 2017-01-10
poisontap - Exploits locked/password protected computers over ... 2017-01-10
kcptun - A Simple UDP Tunnel Based On KCP 2017-01-11
discover-flask - Full Stack Web Development with Flask. ... 2017-01-12
spring-mvc-showcase - Demonstrates the features of the Spring MVC web fr... 2017-01-12
tushare - TuShare is a utility for crawling historical data ... 2017-01-12
raml-spec - RAML Specification http://raml.... 2017-01-12
android-stackblur - Android StackBlur is a library that can perform a ... 2017-01-12
sound-redux - A Soundcloud client built with React / Redux ... 2017-01-12
httpstat - curl statistics made simple 2017-01-12
vim - Vim configuration file and plug-ins 2017-01-12
appframework - The definitive HTML5 mobile javascript framework ... 2017-01-12
BaiduExporter - Assistant for Baidu to export download links to ar... 2017-01-11

 Back to top