Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // PARTITION MODEL (With Partition AND Field schemas)
- // src/models/partition.js
- 'use strict'
- module.exports = Mongoose => {
- // Get all the models
- const { Asset, Group, Role, Account } = Mongoose.models
- const Schema = Mongoose.Schema
- const fieldSchema = new Schema({
- name: {
- type: Schema.Types.String,
- required: true,
- minlength: 3,
- unique: true,
- maxlength: 25,
- trim: true,
- select: true
- }
- })
- const partitionSchema = new Schema({
- name: {
- type: Schema.Types.String
- },
- fields: [ fieldSchema ]
- })
- return Mongoose.model( 'Partition', partitionSchema )
- }
- // ASSET MODEL
- // src/models/asset.js
- 'use strict'
- module.exports = Mongoose => {
- // Get all the models
- const { Group, Role, Account, Partition } = Mongoose.models
- const Schema = Mongoose.Schema
- const modelSchema = new Schema({
- attributes: [{
- _field: {
- type: Schema.Types.ObjectId,
- ref: 'Partition.field' // <-- THIS LINE
- },
- value: {
- type: Schema.Types.Mixed,
- required: true
- }
- }]
- })
- return Mongoose.model( 'Asset', modelSchema )
- }
Add Comment
Please, Sign In to add comment