-
-
Notifications
You must be signed in to change notification settings - Fork 521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to fetch entity and all related ones #486
Comments
Hey @Sytten, basically, calling one returns the first pair of related model i.e. For a one-to-many relation you can expect the behaviour stated above happened. |
I guess then there should be a |
That will complicate the query builder as there is no easy way to limit on one of the join tables. It can be achieved with a subquery like: select releases.id, other_col
from releases
join release_links on ....
where releases.id in (
select releases.id
from releases
where ...
limit 1
) and if the conditions involve both the tables the join should happen also in the subquery. I guess you can do: let result = releases::Entity::find()
.filter(
Condition::any().add(
releases::Column::Id.in_subquery(
Query::select()
.column(releases::Column::Id)
.from(releases::Entity) // if required you can add other conditions here in the subquery
.limit(1)
.to_owned()
)
)
)
.find_with_related(release_links::Entity)
.order_by_desc(releases::Column::ReleasedAt)
.all(conn)
.await?; The result will be of type |
This is a very interesting sugguestion. First of all, if you only need Anyway, thanks @isgj for pointing out this is a non-trivial problem. We have to know the "one" in order to limit the query, so the solution is either 1) two queries or 2) sub query Perhaps removing |
Hey @tyt2y3, do you mean removing From my understanding:
|
Consider the following example (where a release has multiple release_links):
This returns a
Vec<(Model, Vec<Model>)>
. Changing.all
to .one
yields aOption<(Model, Option<Model>)>
.For a One-to-Many relation this is really weird, what is expected is
Option<(Model, Vec<Model>)>
.The text was updated successfully, but these errors were encountered: