HasManyThrough Syntax #1295
Answered
by
iammrsea
popovicieduard
asked this question in
Help
-
Hello, I was wondering what is the syntax for HasManyThrough ? if the syntax for HasMany is:
syntax for HasManyThrough is ? Couldn't find anything in the docs. |
Beta Was this translation helpful? Give feedback.
Answered by
iammrsea
Jul 22, 2020
Replies: 1 comment
-
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>; |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
popovicieduard
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: