Hello,
I'm having trouble with relations between tables,
I have a movies table like this:
Movies.relationMappings = {
showings: {
relation: Model.HasManyRelation,
modelClass: __dirname + '/showings',
join: {
from: 'Movies.id',
to: 'Showings.movieId'
}
}
};
and i have a showings table:
Showings.relationMappings = {
movie: {
relation: Model.BelongsToOneRelation,
modelClass: __dirname + '/movies',
join: {
from: 'Showings.movieId',
to: 'Movies.id'
}
}
};
I'm supposed to have a OneToManyRelation from Movies to Showings and a ManyToOneRelation from Showings to Movies.
I don't know if i'm doing something wrong with my relations but i can't insert datas to movies table using this Movies.query().insert({ title: 'Inception' }). I can't find anything in the docs that relates to this error, and i get Error {} using console.log.
Am I doing something wrong or did i just not understand a thing about how relations work with objectionjs?
Hello,
first thing, i got the error message using Movies.getRelations(), i had this error Movies.relationMappings.showings: join must be an object that maps the columns of the related models together. For example: {from: "SomeTable.id", to: "SomeOtherTable.someModelId"}.
i thought i had to use the model but it was actually the table name so it was:
Movies.relationMappings = {
showings: {
relation: Model.HasManyRelation,
modelClass: __dirname + '/showings',
join: {
from: 'movies.id', <-------- my table is lowercase
to: 'showings.movieId' <-------- same here
}
}
};
Most helpful comment
Hello,
first thing, i got the error message using
Movies.getRelations(), i had this errorMovies.relationMappings.showings: join must be an object that maps the columns of the related models together. For example: {from: "SomeTable.id", to: "SomeOtherTable.someModelId"}.i thought i had to use the model but it was actually the table name so it was: