I am using Aqueudct ORM with data models like so:
A
| (one-one)
B
/ | \ (all many-one)
C C C
and my Tables look like so:
class _A {
B b;
}
class _B {
@Relate(#c1Ref)
C c1;
@Relate(#c2Ref)
C c2;
@Relate(#c3Ref)
C c3;
}
class _C {
ManagedSet<B> c1Ref;
ManagedSet<B> c2Ref;
ManagedSet<B> c3Ref;
}
I want to write a query to fetch big fat A, but I can't figure it out.
So far, I have:
final query = Query<A>(context)
..join(object: (a) => a.b)
//Note the non-cascading dot
.join(object: (b) => b.c1);
This gives me A with B but with only c1. How do I write a query such that I get c2 and c3 as well?
The join method returns a new query object. This query is a child of the original query, and controls the parameters of the query on the joined table. That is, you can apply a where condition to the new query object that applies to the joined table. In your case, you want to assign the new query object to a variable first and then set up each join. I’m on mobile right now so this may not come out great:
final query = Query<A>(context);
final bQuery = query.join(object: (a) => a.b)
..join(object: (b) => b.c1)
..join(object: ( b) => b.c2)
..join(object: (b) => b.c3);
Note that you didn’t really have put this on into a variable here, but I did to illustrate the point. You would execute ‘query’ here, not ‘bQuery’.
Y
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With