thinky
thinky copied to clipboard
add relation to a model as a nested field
Hello,
Suppose I have a model Player:
const Player = thinky.createModel('Player', {
email: type.string().email(),
password: type.string()
});
And I have a relationships:
Player.hasMany(Game, 'hostedGames', 'id', 'hostId');
Player.hasAndBelongsToMany(Game, 'visitedGames', 'id', 'id', {type: 'visitedGames'});
So now response is going to look like:
{
email: '[email protected]',
password: 'aasdsa',
hostedGames: [...],
visitedGames: [...]
}
But what If I want is for the relational fields to be nested, i.e.:
{
email: '[email protected]',
password: 'aasdsa',
football: {
hostedGames: [...],
visitedGames: [...]
}
}
Is it possible to define relationship, so that they will be nested in some object with thinky?
Thanks
This is currently not possible. Joined documents have to lie on the top level. This prevents weird/undesired edge cases like if football contains other fields, things get complicated.