relationship one-to-many #86
-
Hello, I need to create a one-to-many relationship. I searched info in documentation, but I found only many-to-many. My project: I have tables "card" and "articles". I want to get a card with a list of articles, get_join, how I understand, can give only 1 article, but I need many articles. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hello. As I understand, you need to use |
Beta Was this translation helpful? Give feedback.
-
If you use from fastcrud import FastCRUD
card_crud = FastCRUD(Card)
card_with_articles = await card_crud.get_joined(
db=db,
join_model=Article,
join_on=Article.card_id == Card.id,
join_type="left",
join_prefix="article_",
) Or to get multiple results: from fastcrud import FastCRUD
card_crud = FastCRUD(Card)
card_with_articles = await card_crud.get_multi_joined(
db=db,
join_model=Article,
join_on=Article.card_id == Card.id,
join_type="left",
join_prefix="article_",
) |
Beta Was this translation helpful? Give feedback.
Hello. As I understand, you need to use
get_multi_joined
Here is the docs page