Code Monkey home page Code Monkey logo

Comments (2)

Trellian avatar Trellian commented on September 3, 2024

Here is are examples of a base model and it's 'extend'ed model: (sorry, Markdown doesn't seem to be working on the below code...)

IwCountryBaseModel.js:

import {Model} from 'objection';

// Parent Relations
let IwTimezoneBaseModel = require(__dirname + '/IwTimezoneBaseModel');

// Child relations
let IwRegionBaseModel = require(__dirname + '/IwRegionBaseModel');

/**

  • WARNING: This is a generated file, do NOT edit it,
  •      you will lose your edits when it is next regenerated
    

*/

export default class IwCountryBaseModel extends Model {

// Table name is the only required property.
static get tableName() {
return 'IwCountry';
}

constructor () {
}

// 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/.

static get jsonSchema () {
return {
type: 'object',
required: [

     'name',
     'country_code',
     'dial_code',
     'timezone_id'
  ],

  properties: {
        
    id: {type: 'integer'},            
    name: {type: 'string'},            
    country_code: {type: 'string'},            
    dial_code: {type: 'string'},            
    timezone_id: {type: 'integer'}
  }
};

}

// This object defines the relations to other models.
static get relationMappings() {

return {

    // Parent Relations    
        
    iwTimezones: {
        relation: Model.BelongsToOneRelation, 
        modelClass: __dirname + IwTimezone,
            join: {
                from: 'IwCountry.timezone_id',
                to: 'IwTimezone.id'
            }
        },
    
    // Child Relations and Many-toMany Relations    

    iwRegions: {
        relation: Model.HasManyRelations, 
        modelClass: __dirname + IwRegion,
        join: {
            from: 'IwCountry.id',
            to: 'IwRegion.country_id'
        }
    }

};

}
}

and IwCountryModel.js:

import IwCountryBaseModel from ('./base/IwCountryBaseModel.js');

/**

  • NOTICE: This file inherits from the base Model and can be modified. It won't be overwritten at the next generate
    */

export default class IwCountry extends IwCountryBaseModel {

// Add/Override properties here... it won't be overwritten

}

from objection-graphql.

Trellian avatar Trellian commented on September 3, 2024

My bad, sorry... syntax error on my part :o

from objection-graphql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.