This repository has been archived by the owner on Mar 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 278
join user's cards and sort users, by card's count. #935
Comments
bahramee
changed the title
sort data & join object
join user's cards and sort users, by card's count.
Jan 16, 2021
You can not do that using the ORM at the moment and it would be a big undertaking for it to be implemented. final cardQuery = Query<User>(context)
..where((u) => u.company).identifiedBy(companyId)
//..join(object: (u) => u.company) uncomment this row only if you want the company to be returned by the query
..join(set: (u) => u.card); |
thanks for fast answer.
can you help me please for optimize that ? |
This is if you don't want to include the company rank: bool isOwner = userId != null;
companyScores.user.sort((u1, u2) => u1.card.length - u2.card.length);
return companyScores.user.map((user) => UserScore(
userId: user.id,
username: user.username,
score: user.card.length,
productId: productId,
isOwner: isOwner,
//company rank will be the the index in the newly create array
)).toList(); |
This is if you want score: bool isOwner = userId != null;
companyScores.user.sort((u1, u2) => u1.card.length - u2.card.length);
final userRank = <UserScore>[];
for(var i = 0; i < companyScores.user.length; ++i) {
userRank.add(UserScore(
userId: user.id,
username: user.username,
score: user.card.length,
productId: productId,
isOwner: isOwner,
companyRank: i,
))
}
return userRank; |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
hello
i have a usecase with this details:
a query on "User"s wich every users have many cards wich used by user.
question is here:
how can i sort user by his card's count.
and this is my current query...
The text was updated successfully, but these errors were encountered: