123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- var structure = require('./context.fixture');
- /**
- * Context Fixture for a Many To Many Relationship
- */
- module.exports = function() {
- var context = structure;
- context.identity = 'foo';
- context.primaryKey = 'id';
- context.connections = {
- my_foo: {
- config: {},
- _adapter: {},
- _collections: []
- }
- };
- // Build Out Model Definitions
- var models = {
- foo: {
- identity: 'foo',
- datastore: 'my_foo',
- attributes: {
- id: {
- type: 'integer',
- autoIncrement: true,
- primaryKey: true,
- unique: true
- },
- name: {
- type: 'string'
- },
- bars: {
- collection: 'bar',
- via: 'foos',
- dominant: true
- },
- foobars: {
- collection: 'baz' ,
- via: 'foo',
- dominant: true
- }
- }
- },
- bar: {
- identity: 'bar',
- datastore: 'my_foo',
- attributes: {
- id: {
- type: 'integer',
- autoIncrement: true,
- primaryKey: true,
- unique: true
- },
- name: {
- type: 'string'
- },
- foos: {
- collection: 'foo',
- via: 'bars'
- }
- }
- },
- baz: {
- identity: 'baz',
- datastore: 'my_foo',
- attributes: {
- id: {
- type: 'integer',
- autoIncrement: true,
- primaryKey: true,
- unique: true
- },
- foo: {
- model: 'foo'
- }
- }
- },
- bar_foos__foo_bars: {
- identity: 'bar_foos__foo_bars',
- datastore: 'my_foo',
- tables: ['bar', 'foo'],
- junctionTable: true,
- attributes: {
- id: {
- primaryKey: true,
- autoIncrement: true,
- type: 'integer'
- },
- bar_foos: {
- columnName: 'bar_foos',
- type: 'integer',
- foreignKey: true,
- references: 'bar',
- on: 'id',
- via: 'foo_bars',
- groupBy: 'bar'
- },
- foo_bars: {
- columnName: 'foo_bars',
- type: 'integer',
- foreignKey: true,
- references: 'foo',
- on: 'id',
- via: 'bar_foos',
- groupBy: 'foo'
- }
- }
- }
- };
- // Set context collections
- context.waterline.collections = models;
- // Set collection attributes
- context._attributes = models.foo.attributes;
- context.attributes = context._attributes;
- context.waterline.connections = context.connections;
- // Build Up Waterline Schema
- context.waterline.schema.foo = {
- identity: 'foo',
- datastore: 'my_foo',
- attributes: {
- id: {
- type: 'integer',
- autoIncrement: true,
- primaryKey: true,
- unique: true
- },
- name: {
- type: 'string'
- },
- bars: {
- collection: 'bar_foos__foo_bars',
- references: 'bar_foos__foo_bars',
- on: 'bar_foos'
- },
- foobars: {
- collection: 'baz',
- references: 'baz',
- on: 'foo_id'
- }
- }
- };
- context.waterline.schema.bar = {
- identity: 'bar',
- datastore: 'my_foo',
- attributes: {
- id: {
- type: 'integer',
- autoIncrement: true,
- primaryKey: true,
- unique: true
- },
- name: {
- type: 'string'
- },
- foos: {
- collection: 'bar_foos__foo_bars',
- references: 'bar_foos__foo_bars',
- on: 'foo_bars'
- }
- }
- };
- context.waterline.schema.baz = {
- identity: 'baz',
- datastore: 'my_foo',
- attributes: {
- id: {
- type: 'integer',
- autoIncrement: true,
- primaryKey: true,
- unique: true
- },
- foo: {
- columnName: 'foo_id',
- type: 'integer',
- foreignKey: true,
- references: 'foo',
- on: 'id'
- }
- }
- };
- context.waterline.schema.bar_foos__foo_bars = {
- identity: 'bar_foos__foo_bars',
- datastore: 'my_foo',
- tables: ['bar', 'foo'],
- junctionTable: true,
- attributes: {
- id: {
- primaryKey: true,
- autoIncrement: true,
- type: 'integer'
- },
- bar_foos: {
- columnName: 'bar_foos',
- type: 'integer',
- foreignKey: true,
- references: 'bar',
- on: 'id',
- via: 'foo_bars',
- groupBy: 'bar'
- },
- foo_bars: {
- columnName: 'foo_bars',
- type: 'integer',
- foreignKey: true,
- references: 'foo',
- on: 'id',
- via: 'bar_foos',
- groupBy: 'foo'
- }
- }
- };
- return context;
- };
|