Comments (5)
I can give more insights if required, I just need to know it's not supported or I'm doing something wrong?
from sleekdb.
Hi @armanist thank you for your question.
Sorry for the late response.
If you want to use select after a join it should be possible.
You can read more about that at https://sleekdb.github.io/#/execution-order
Could you please provide an example result without the select? Perhaps I can then help you with what is going wrong 😊
from sleekdb.
@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 userBiographies
is an array of documents.
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 userBiographies.*.age
or a built-in select function to get the first result, with the next major update. 😊
Instead of saving the userBiography
in another "table" (store) and handle the situation the "relational"-way, you should think about saving the userBiography
directly in the user
document (the document/nosql-based-approach).
{
"_id": 2,
"name": "Tom",
"userBiography": {
"age": 18,
"work": "some work"
},
"address": {
"street": "some street",
"postalCode": "0129479",
}
}
Hope I could help 😁
from sleekdb.
Hi @Timu57, thank you very much for great details, I will try your suggested way above ->select(['age' => 'userBiographies.0.age'])
and will let you know here, the wildcard implementation will be great addition though ( userBiographies.*
). Meantime you can have look at SleekDB integration to the framework we are developing https://github.com/softberg/quantum-php-core/tree/master/src/Libraries/Database/Sleekdb.
from sleekdb.
I'm closing this issue for now. Feel free to reopen it if needed.
from sleekdb.
Related Issues (20)
- Math & Logic operations HOT 2
- nested column select and distinct return empty array HOT 3
- simple join approach
- SleekDB Extension of builtin "named functions" by users
- Allow to use UUIDs as primary keys HOT 2
- How to Run SleekDB HOT 4
- JSON Wildcard Notation HOT 2
- Incorrect escaping of characters?
- Class 'SleekDB\Store' not found HOT 2
- how we do search with join HOT 6
- Searching for value in array. HOT 2
- [Feature Request] Simple key-value lookup HOT 1
- [Feature Request] Searching from multiple stores HOT 1
- [SUGGESTION] please set config:timeout default to false HOT 2
- How to set special chars? HOT 7
- Use SleekDB as a readonly store HOT 2
- updateById method undefined HOT 3
- Group by Date HOT 1
- replace file HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sleekdb.