BVB Source Codes

waterline Show is-exclusive.js Source code

Return Download waterline: download is-exclusive.js Source code - Download waterline Source code - Type:.js
  1. /**
  2.  * Module dependencies
  3.  */
  4.  
  5. var util = require('util');
  6. var assert = require('assert');
  7. var _ = require('@sailshq/lodash');
  8. var getAttribute = require('./get-attribute');
  9.  
  10.  
  11. /**
  12.  * isExclusive()
  13.  *
  14.  * Determine whether this association is "exclusive" -- meaning that it is
  15.  * a two-way, plural ("collection") association, whose `via` points at a
  16.  * singular ("model") on the other side.
  17.  *
  18.  * > Note that "through" associations do not count.  Although the "via" does
  19.  * > refer to a singular ("model") association in the intermediate junction
  20.  * > model, the underlying logical association is still non-exclusive.
  21.  * > i.e. the same child record can be added to the "through" association
  22.  * > of multiple different parent records.
  23.  *
  24.  * ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  25.  * @param {String} attrName        [the name of the association in question]
  26.  * @param {String} modelIdentity   [the identity of the model this association belongs to]
  27.  * @param {Ref} orm                [the Waterline ORM instance]
  28.  * ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  29.  * @returns {Boolean}
  30.  */
  31.  
  32. module.exports = function isExclusive(attrName, modelIdentity, orm) {
  33.  
  34.   assert(_.isString(attrName), 'Must specify `attrName` as a string.  But instead, got: '+util.inspect(attrName, {depth:5})+'');
  35.   assert(_.isString(modelIdentity), 'Must specify `modelIdentity` as a string.  But instead, got: '+util.inspect(modelIdentity, {depth:5})+'');
  36.   assert(!_.isUndefined(orm), 'Must pass in `orm` (a reference to the Waterline ORM instance).  But instead, got: '+util.inspect(orm, {depth:5})+'');
  37.  
  38.  
  39.   //  鈺  鈺斺晲鈺椻晹鈺愨晽鈺︹晹鈺  鈺 鈺︹晹鈺愨晽  鈹屸攢鈹愨攲鈹€鈹愨攲鈹€鈹愨攲鈹€鈹愨攲鈹€鈹愨敩鈹屸攢鈹愨攲鈹攼鈹攲鈹€鈹愨攲鈹愨攲   鈹   鈹屸敩鈹愨攲鈹€鈹愨攲鈹攼鈹屸攢鈹愨敩  鈹屸攢鈹
  40.   //  鈺  鈺 鈺戔晳 鈺戔暊鈺┾晽  鈺 鈺戔暊鈺愨暆  鈹溾攢鈹も敂鈹€鈹愨敂鈹€鈹愨攤 鈹傗攤  鈹傗敎鈹€鈹 鈹 鈹傗攤 鈹傗攤鈹傗攤  鈹屸敿鈹€  鈹傗攤鈹傗攤 鈹 鈹傗攤鈹溾敜 鈹  鈹斺攢鈹
  41.   //  鈺┾晲鈺濃暁鈺愨暆鈺氣晲鈺濃暕 鈺  鈺氣晲鈺濃暕    鈹 鈹粹敂鈹€鈹樷敂鈹€鈹樷敂鈹€鈹樷敂鈹€鈹樷敶鈹 鈹 鈹 鈹粹敂鈹€鈹樷敇鈹斺敇  鈹斺敇   鈹 鈹粹敂鈹€鈹樷攢鈹粹敇鈹斺攢鈹樷敶鈹€鈹樷敂鈹€鈹
  42.  
  43.   // Look up the containing model for this association, and the attribute definition itself.
  44.   var attrDef = getAttribute(attrName, modelIdentity, orm);
  45.  
  46.   assert(attrDef.model || attrDef.collection,
  47.     'Attempting to check whether attribute `'+attrName+'` of model `'+modelIdentity+'` '+
  48.     'is an "exclusive" association, but it\'s not even an association in the first place!'
  49.   );
  50.  
  51.  
  52.  
  53.  
  54.   //  鈹屸攼鈹屸攲鈹€鈹愨敩 鈹   鈺斺晲鈺椻暒 鈺︹晹鈺愨晽鈺斺晲鈺椻暒鈺斺晲  鈺︹晹鈺︹晽  鈺斺晲鈺椻暒 鈺︹晹鈺︹晽
  55.   //  鈹傗攤鈹傗攤 鈹傗攤鈹傗攤   鈺  鈺犫晲鈺b晳鈺 鈺  鈺犫暕鈺  鈺 鈺   鈺 鈺戔晳 鈺 鈺
  56.   //  鈹樷敂鈹樷敂鈹€鈹樷敂鈹粹敇鈹  鈺氣晲鈺濃暕 鈺┾暁鈺愨暆鈺氣晲鈺濃暕 鈺  鈺 鈺   鈺氣晲鈺濃暁鈺愨暆 鈺
  57.  
  58.   // If this association is singular, then it is not exclusive.
  59.   if (!attrDef.collection) {
  60.     return false;
  61.   }//-鈥
  62.  
  63.   // If it has no `via`, then it is not two-way, and also not exclusive.
  64.   if (!attrDef.via) {
  65.     return false;
  66.   }//-鈥
  67.  
  68.   // If it has a "through" junction model defined, then it is not exclusive.
  69.   if (attrDef.through) {
  70.     return false;
  71.   }//-鈥
  72.  
  73.   // If its `via` points at a plural association, then it is not exclusive.
  74.   // > Note that, to do this, we look up the attribute on the OTHER model
  75.   // > that is pointed at by THIS association's `via`.
  76.   var viaAttrDef = getAttribute(attrDef.via, attrDef.collection, orm);
  77.   if (viaAttrDef.collection) {
  78.     return false;
  79.   }//-鈥
  80.  
  81.   // Otherwise, its `via` must be pointing at a singular association, so it's exclusive!
  82.   return true;
  83.  
  84. };
  85.  
  86.  
  87. // Quick test:
  88. /*```
  89. require('./lib/waterline/utils/ontology/is-exclusive')('pets', 'user', { collections: { user: { attributes: { id: { type: 'string', required: true, unique: true }, age: { type: 'number', required: false }, foo: { type: 'string', required: true }, pets: { collection: 'pet', via: 'owner' } }, primaryKey: 'id', hasSchema: true}, pet: { attributes: { id: { type:'number', required: true, unique: true }, owner: { model: 'user' } }, primaryKey: 'id', hasSchema: true } } });
  90. ```*/
  91.  
downloadis-exclusive.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