Skip to content

HasManyThrough Syntax #1295

Answered by iammrsea
popovicieduard asked this question in Help
Discussion options

You must be logged in to vote

For instance, you have an app that has the following models: User, Restaurant and Dish. Here, a user hasOne restaurant and that restaurant has many dishes associated with it. Invariably, same user has many dishes through restaurant. This is how you could establish the relationships:

//Dish.ts
@belongsTo(()=>Restaurant)
public restaurant: BelongsTo<typeof Restaurant>;

//Restaurant.ts
@belongsTo(()=>User)
public user: BelongsTo<typeof User>;

@hasMany(()=>Dish)
public dishes: HasMany<typeof Dish>;

//User.ts
@hasOne(()=>Restaurant)
public restaurant: HasOne<typeof Restaurant>;

@hasManyThrough([()=>Dish, ()=>Restaurant])
public dishes: HasManyThrough<typeof Dish>;

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by popovicieduard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants