https://github.com/tourware/sails-hook-mixins
Mixins (horizontal inheritance) for sails models.
https://github.com/tourware/sails-hook-mixins
horizontal inheritance mixin-framework mixins sails-model sailsjs
Last synced: 4 months ago
JSON representation
Mixins (horizontal inheritance) for sails models.
- Host: GitHub
- URL: https://github.com/tourware/sails-hook-mixins
- Owner: tourware
- Created: 2017-01-02T13:02:38.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-04T15:51:04.000Z (over 9 years ago)
- Last Synced: 2025-10-20T11:18:06.695Z (8 months ago)
- Topics: horizontal, inheritance, mixin-framework, mixins, sails-model, sailsjs
- Language: JavaScript
- Size: 3.91 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Mixins (horizontal inheritance) for sails models.
---
## Getting started
* Add a folder `api/mixins/` to your project
* Add you first mixin, for example `api/mixins/hasCoordinates.js`
* Define your attributes which are used by multiple models
#### Defining shared attributes
Lets take our example: `api/mixins/hasCoordinates.js`
```js
module.exports = {
attributes: {
lat: {
type: 'float'
},
lng: {
type: 'float'
}
};
```
#### Use the mixin in the model
For example the an address model `api/models/Address.js` needs the `lat` and `lng` attributes:
```js
module.exports = {
mixins: [
'hasCoordinates'
],
attributes: {
street: {
type: 'string',
required: true
},
zipcode: {
type: 'string'
},
city: {
type: 'string'
}
}
};
```
and a Point Of Interest model needs the `lat` and `lng` attributes:: `api/models/PointOfInterest.js`
```js
module.exports = {
mixins: [
'hasCoordinates'
],
attributes: {
title: {
type: 'string',
required: true
},
description: {
type: 'string'
}
}
};
```