Let's say I have two tables :
People:
name : place
----- : ------
ben : park
phil : office
Food:
food_place : vegetable
----------- : ---------
ben@park : carrots
phil@office : potatoes
I'd like to create a Relation Mapping, I tried:
static get relationMappings() {
const knex = People.knex();
return {
food: {
relation: Model.BelongsToOneRelation,
modelClass: `${__dirname}/Food`,
join: {
from: knex.raw('CONCAT(people.name, "@", people.place)'),
to: 'food.food_place',
},
},
};
}
That didn't work because objection expected the from
property to match column name (Error: People.relationMappings.food: join.from must have format TableName.columnName
).
The idea was to join tables like:
INNER JOIN Food ON Food.food_place = CONCAT(people.name, "@", people.place)
QUESTION : Is there a was i can do this with relation mappings, or should i use modifiers instead ?