Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
relation: objection.ManyToManyRelation,
modelClass: Movie,
join: {
from: 'Person.id',
through: {
from: 'Person_Movie.actorId',
to: 'Person_Movie.movieId'
},
to: 'Movie.id'
}
}
};
Animal.relationMappings = {
owner: {
relation: objection.BelongsToOneRelation,
modelClass: Person,
join: {
from: 'Animal.ownerId',
to: 'Person.id'
}
}
}
return {
Person: Person,
Animal: Animal,
Movie: Movie
};
}
Person.tableName = 'Person';
Animal.tableName = 'Animal';
Movie.tableName = 'Movie';
Person.knex(knex);
Animal.knex(knex);
Movie.knex(knex);
Person.prototype.fullName = function () {
return this.firstName + ' ' + this.lastName;
};
Person.relationMappings = {
parent: {
relation: objection.BelongsToOneRelation,
modelClass: Person,
join: {
from: 'Person.pid',
to: 'Person.id'
}
},
children: {
relation: objection.HasManyRelation,
modelClass: Person,
join: {
from: 'Person.id',
to: 'Person.pid'
}
},
static get relationMappings() {
return {
parent: {
relation: objection.BelongsToOneRelation,
modelClass: Person,
join: {
from: 'Person.pid',
to: 'Person.id'
}
},
pets: {
relation: objection.HasManyRelation,
modelClass: Animal,
join: {
from: 'Person.id',
to: 'Animal.ownerId'
}
},
static get tableName() {
return 'Movie';
}
}
Person.knex(knex);
Animal.knex(knex);
Movie.knex(knex);
Person.prototype.fullName = function() {
return this.firstName + ' ' + this.lastName;
};
Person.relationMappings = {
parent: {
relation: objection.BelongsToOneRelation,
modelClass: Person,
join: {
from: 'Person.pid',
to: 'Person.id'
}
},
pets: {
relation: objection.HasManyRelation,
modelClass: Animal,
join: {
from: 'Person.id',
to: 'Animal.ownerId'
}
},
_relationField(modelData, relation) {
if (relation instanceof objection.HasOneRelation
|| relation instanceof objection.BelongsToOneRelation
|| relation instanceof objection.HasOneThroughRelation) {
return {
type: this._typeForModel(modelData),
args: _.omit(modelData.args, OMIT_FROM_RELATION_ARGS),
};
} else if (relation instanceof objection.HasManyRelation || relation instanceof objection.ManyToManyRelation) {
return {
type: new GraphQLList(this._typeForModel(modelData)),
args: _.omit(modelData.args, OMIT_FROM_RELATION_ARGS),
};
}
throw new Error(`relation type "${relation.constructor.name}" is not supported`);
}