Comments (2)
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.
My bad, sorry... syntax error on my part :o
from objection-graphql.
Related Issues (20)
- Fastify integretation?
- How can I apply order by on two or more columns
- eager is not a function HOT 1
- How to handle jsonSchema relations?
- How to retrieve DB context in a Mutation with `extendWithMutations` HOT 7
- Problems with `build()`, relation class in Models are not being recognized
- Relationship class not being recognized on a Model during `build()` HOT 1
- How to write mutation in Schema Defition Language HOT 3
- Mutation Tests are not passing correctly, the mutation is not actually written to the test DB
- Basic problem with standard Objection express-es6 example and objection-graphql HOT 1
- Support facebook/dataloader in GraphQL schema HOT 1
- extendWithMutations function takes the last mutation passed always HOT 1
- Error: relation type "HasManyRelation" is not supported
- Anyone have a small sample project that implements mutations?
- Relations not loading after mutation HOT 3
- Is there any way to implement resolvers in the jsonSchema?
- Set writeOnly and readOnly jsonSchema's value options HOT 1
- How to implement access control? HOT 2
- How to implement virtual Attributes? HOT 1
- Return empty array instead of null
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from objection-graphql.