How to have an abstract class in sails.js

343 views Asked by At

How can I create an "abstract" model in sails.js? Basically I want to create a model with common attributes. Then create a new model using that "abstract" model as the base, having those common attributes available in the new model as well as save to the database as part of the new model.

1

There are 1 answers

0
Mahdi Imani On

waterline ORM (sailjs v1.0.4) recommend to use this kind of model defenition

https://sailsjs.com/documentation/concepts/models-and-orm/models

in example you must define a model in an object with specify attribute like 'type, isIn, required and ... '

module.exports = {

  attributes: {
   
    name: {
      type: 'string'
    },
    
    wingspan: {
      type: 'number',
      required: true,
      columnType: 'FLOAT'
    },
    
    wingspanUnits: {
      type: 'string',
      isIn: ['cm', 'in', 'm', 'mm'],
      defaultsTo: 'cm'
    },
    
    knownDialects: {
      collection: 'Dialect'
    } 
  }
};