Replies: 6 comments
-
|
Beta Was this translation helpful? Give feedback.
-
@jenssegers what do you think try to use codecov.io for coverage reports? |
Beta Was this translation helpful? Give feedback.
-
How about add ability to hydrate nested objects? For example:
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class User extends Eloquent
{
/**
* {@inheritdoc}
*/
protected $collection = 'users';
/**
* @return \Jenssegers\Mongodb\Relations\EmbedsMany
*/
public function books()
{
return $this->embedsMany(Book::class, null, null, 'books');
}
} use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Book extends Eloquent
{
} So, Book::where('name', 'book1')->get(); will returns nothing (not a surprise). To do what I want I'm using "snippets" like this one: $results = User::getQuery()->raw(function ($collection) {
return $collection->aggregate([
[
'$project' => [ 'books' => 1 ],
],
[
'$match' => [
'books.name' => 'book1',
]
],
[
'$unwind' => '$books',
],
[
'$replaceRoot' => [ 'newRoot' => '$books' ],
]
]);
});
if ($results instanceof \MongoDB\Driver\Cursor) {
$results = iterator_to_array($results, false);
$books = Book::hydrate($results);
} For me, main disadvantages of this approach are:
|
Beta Was this translation helpful? Give feedback.
-
@askobara embedded relationships might be deprecated soon and completely removed, there is no final decision just yet. |
Beta Was this translation helpful? Give feedback.
-
Oh, what a reason? Hard to maintains or it's bad practice? |
Beta Was this translation helpful? Give feedback.
-
@askobara it's not a bad practice, you'll be still able to embed documents as before, however without eloquent magic which is custom code and yes it's hard to maintain. Let me give you an example, you've embedded 10k books in one author document, does pagination works perfectly? Of course not, because it fetches completely that document and after that it does a fake "pagination" each time. As I've said there is no final decision just yet, however even if we deprecate it, it will be completely new version probably version 3.7 or 4. |
Beta Was this translation helpful? Give feedback.
-
Hi guys,
If you've any suggestion or feature request, please suggest it here.
Thanks.
Join our Slack channel here
Beta Was this translation helpful? Give feedback.
All reactions