sails-hook-mixins

0.0.2 • Public • Published

Typisch Touristik

Mixins (horizontal inheritance) for sails models.

Travis Status Dependency Status Version Status


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

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:

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

module.exports = {

  mixins: [
    'hasCoordinates'
  ],

  attributes: {
    title: {
      type: 'string',
      required: true
    },

    description: {
      type: 'string'
    }
  }
};

Package Sidebar

Install

npm i sails-hook-mixins

Weekly Downloads

1

Version

0.0.2

License

MIT

Last publish

Collaborators

  • touristik