context.belongsTo.fixture.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. var structure = require('./context.fixture');
  2. /**
  3. * Context Fixture for a Belongs To Relationship
  4. */
  5. module.exports = function() {
  6. var context = structure;
  7. // Name the collection
  8. context.identity = 'foo';
  9. context.primaryKey = 'id';
  10. // Set collection attributes
  11. context._attributes = {
  12. id: {
  13. type: 'integer',
  14. autoIncrement: true,
  15. primaryKey: true,
  16. unique: true
  17. },
  18. name: { type: 'string' },
  19. bars: {
  20. collection: 'bar',
  21. via: 'foo'
  22. }
  23. };
  24. // Build a mock global schema object
  25. context.waterline.schema = {
  26. foo: {
  27. identity: 'foo',
  28. attributes: {
  29. name: 'string',
  30. bars: {
  31. collection: 'bar',
  32. references: 'bar',
  33. on: 'foo_id',
  34. onKey: 'foo'
  35. },
  36. id: {
  37. type: 'integer',
  38. autoIncrement: true,
  39. primaryKey: true,
  40. unique: true
  41. }
  42. }
  43. },
  44. bar: {
  45. identity: 'bar',
  46. attributes: {
  47. name: 'string',
  48. id: {
  49. type: 'integer',
  50. autoIncrement: true,
  51. primaryKey: true,
  52. unique: true
  53. },
  54. foo: {
  55. columnName: 'foo_id',
  56. type: 'integer',
  57. foreignKey: true,
  58. references: 'foo',
  59. on: 'id',
  60. onKey: 'id'
  61. }
  62. }
  63. }
  64. };
  65. // Build global collections
  66. context.waterline.collections.foo = {
  67. identity: 'foo',
  68. _attributes: context._attributes
  69. };
  70. context.waterline.collections.bar = {
  71. identity: 'bar',
  72. _attributes: {
  73. name: { type: 'string' },
  74. foo: { model: 'foo' },
  75. id: {
  76. type: 'integer',
  77. autoIncrement: true,
  78. primaryKey: true,
  79. unique: true
  80. }
  81. }
  82. };
  83. return context;
  84. };