How to use the objection.Model.extend function in objection

To help you get started, we’ve selected a few objection examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Vincit / objection.js / examples / express / models / Animal.js View on Github external
var Model = require('objection').Model;

/**
 * @extends Model
 * @constructor
 */
function Animal() {
  Model.apply(this, arguments);
}

Model.extend(Animal);
module.exports = Animal;

// Table name is the only required property.
Animal.tableName = 'Animal';

// Optional JSON schema. This is not the database schema! Nothing is generated
// based on this. This is only used for validation. Whenever a model instance
// is created it is checked against this schema. http://json-schema.org/.
Animal.jsonSchema = {
  type: 'object',
  required: ['name'],

  properties: {
    id: {type: 'integer'},
    ownerId: {type: ['integer', 'null']},
    name: {type: 'string', minLength: 1, maxLength: 255},
github Vincit / objection.js / examples / express / models / Person.js View on Github external
var Model = require('objection').Model;
var Animal = require('./Animal')
var Movie = require('./Movie')

/**
 * @extends Model
 * @constructor
 */
function Person() {
  Model.apply(this, arguments);
}

Model.extend(Person);
module.exports = Person;

// Table name is the only required property.
Person.tableName = 'Person';

// Optional JSON schema. This is not the database schema! Nothing is generated
// based on this. This is only used for validation. Whenever a model instance
// is created it is checked against this schema. http://json-schema.org/.
Person.jsonSchema = {
  type: 'object',
  required: ['firstName', 'lastName'],

  properties: {
    id: {type: 'integer'},
    parentId: {type: ['integer', 'null']},
    firstName: {type: 'string', minLength: 1, maxLength: 255},
github Vincit / objection.js / examples / jsonb / models / Hero.js View on Github external
var Model = require('objection').Model;

/**
 * @extends Model
 * @constructor
 */
function Hero() {
  Model.apply(this, arguments);
}

Model.extend(Hero);
module.exports = Hero;

// Table name is the only required property.
Hero.tableName = 'Hero';

Hero.jsonSchema = {
  type: 'object',
  required: ['name'],

  properties: {
    id: { type: 'integer' },
    name: { type: 'string' },
    details: { type: ['object', 'array', 'null'] },
    homeId: { type: 'integer' }
  }
};
github Vincit / objection.js / examples / express / models / Movie.js View on Github external
var Model = require('objection').Model;

/**
 * @extends Model
 * @constructor
 */
function Movie() {
  Model.apply(this, arguments);
}

Model.extend(Movie);
module.exports = Movie;

// Table name is the only required property.
Movie.tableName = 'Movie';

// Optional JSON schema. This is not the database schema! Nothing is generated
// based on this. This is only used for validation. Whenever a model instance
// is created it is checked against this schema. http://json-schema.org/.
Movie.jsonSchema = {
  type: 'object',
  required: ['name'],

  properties: {
    id: {type: 'integer'},
    name: {type: 'string', minLength: 1, maxLength: 255}
  }