sails-hook-nested

0.3.0 • Public • Published
Predrag Stojadinovic

sails-hook-nested

build status codacy coverage dependencies npm

Nested attributes for sails models.


TODO

Getting started

Add a nested object/array definitions to your model.

These attributes must conform to the forgJs syntax, for now!

module.exports = {
	attributes: {

		// nested attributes definitions
		arrayOfObjects: {
			type: 'nested_array',
			of: {
				wa: {type: 'int', optional: true},
				res: {type: 'string'},
				entry: {type: 'int'},
				correct: 'boolean',
				deep: {
					type: 'nested_object',
					of: {
						ten: {type: 'int', min: 0, max: 10, optional: true},
						shoo: {type: 'string', minLength: 6, maxLength: 22},
						maybe: 'boolean',
						deepArray: {
							type: 'nested_array',
							of: {
								wa: {type: 'int', optional: true},
								res: {type: 'string'},
								entry: {type: 'int'},
								correct: 'boolean',
								deeper: {
									type: 'nested_object',
									of: {
										ten: {type: 'int', min: 0, max: 10, optional: true},
										shoo: {type: 'string', minLength: 6, maxLength: 22},
										maybe: 'boolean',
										evenDeeper: {
											type: 'nested_object',
											of: {
												ten: {type: 'int', min: 0, max: 10, optional: true},
												shoo: {type: 'string', minLength: 6, maxLength: 22},
												maybe: 'boolean'
											}
										}
									}
								}
							},
							required: true
						}
					}
				}
			},
			required: true
		},
		nestedAttributes: {
			type: 'nested_object',
			of: {
				ten: {type: 'int', min: 0, max: 10, optional: true},
				shoo: {type: 'string', minLength: 6, maxLength: 22},
				maybe: 'boolean',
				deep: {
					type: 'nested_object',
					of: {
						ten: {type: 'int', min: 0, max: 10, optional: true},
						shoo: {type: 'string', minLength: 6, maxLength: 22},
						maybe: 'boolean',
						deeper: {
							type: 'nested_object',
							of: {
								ten: {type: 'int', min: 0, max: 10, optional: true},
								shoo: {type: 'string', minLength: 6, maxLength: 22},
								maybe: 'boolean',
								evenDeeper: {
									type: 'nested_object',
									of: {
										ten: {type: 'int', min: 0, max: 10, optional: true},
										shoo: {type: 'string', minLength: 6, maxLength: 22},
										maybe: 'boolean'
									}
								}
							}
						}
					}
				}
			}
		},

		// regular sails attributes
		num: {
			type: 'number'
		},
		word: {
			type: 'string'
		}
	}
};

Package Sidebar

Install

npm i sails-hook-nested

Weekly Downloads

1

Version

0.3.0

License

MIT

Unpacked Size

54.8 kB

Total Files

7

Last publish

Collaborators

  • dzoni77
  • stojadinovicp