-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Select with alias at join #246
Comments
I can give more insights if required, I just need to know it's not supported or I'm doing something wrong? |
Hi @armanist thank you for your question. If you want to use select after a join it should be possible. Could you please provide an example result without the select? Perhaps I can then help you with what is going wrong 😊 |
@armanist I think I know what the problem is: $users = $userQueryBuilder
->join(function($user) use ($userBuiographyStore) {
return $userBiographyStore->findBy(["user", "=", $user["_id"]]);
}, "userBiographies")
->getQuery()
->fetch();
// $users should be something like this:
// {'_id' => 2, 'name' => 'Tom', 'userBiographies' => [{'age' => 16, ...}, {'age' => 18, ...}, ...], ... } As you can see Now you can try the following to select: $users = $userQueryBuilder
->select(['age' => 'userBiographies.0.age'])
->join(function($user) use ($userBuiographyStore) {
return $userBiographyStore->findBy(["user", "=", $user["_id"]]);
}, "userBiographies")
->getQuery()
->fetch();
// or with a custom select function if the above does not work
$users = $userQueryBuilder
->select([
'age' => function($user) {
return $user['userBiography'][0]['age'];
}
])
->join(function($user) use ($userBuiographyStore) {
return $userBiographyStore->findBy(["user", "=", $user["_id"]]);
}, "userBiographies")
->getQuery()
->fetch(); We are aware of the problem of handling documents within arrays. We plan to implement a wildcard like Instead of saving the {
"_id": 2,
"name": "Tom",
"userBiography": {
"age": 18,
"work": "some work"
},
"address": {
"street": "some street",
"postalCode": "0129479",
}
} Hope I could help 😁 |
Hi @Timu57, thank you very much for great details, I will try your suggested way above |
I'm closing this issue for now. Feel free to reopen it if needed. |
In the documentation (QueryBuilder section) there is an example how to use
select()
method and filter the columns.There is no much insights about it, but assuming the
userBiography
is a table that was joined withusers
table?When I'm trying to use dot notation like
userBiography.age
in the result set it's alwaysnull
Example 2
Retrieve just the age of all users as age.
Note: The age of the user is stored in a nested array and we use an alias.
The text was updated successfully, but these errors were encountered: