You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I learned about this pattern when searching about when/what to embed etc. and I think it could be a great addition to doctrine-odm.
I'm not sure how it could be implemented yet but having an Attribute #[SubSet(number:5, sort: DESC)] in addition to an attribute #[ReferenceMany] to store the 5 most recents referenced directly on an embed could reduce read operation on the db.
I learned about this pattern on the mongodb website here and here
The text was updated successfully, but these errors were encountered:
I believe this resembles #2252 and also suffers the same challenge: tracking changes. ODM would need to know that a (let's say) review has been changed and update its product accordingly.
Also, while less sexy than an attribute, the pattern is already doable and quite elegant:
class Product
{
#[ReferenceMany(targetClass: Review::class)]
private Collection $reviews;
#[EmbedMany(targetClass: PartialReview::class)]
private Collection $recentReviews;
public function addReview(Review $review)
{
$this->reviews[] = $review;
$this->recentReviews[] = new PartialReview($review);
// maybe pop one last recent reviews if there's too many
}
}
You could even hide capping recent reviews with a custom collection :)
Yeah tracking changes and knowing when to fetch the whole references list is what made me think about the most and couldn't think any good solutions for that.
Feature Request
Summary
I learned about this pattern when searching about when/what to embed etc. and I think it could be a great addition to doctrine-odm.
I'm not sure how it could be implemented yet but having an Attribute
#[SubSet(number:5, sort: DESC)]
in addition to an attribute#[ReferenceMany]
to store the 5 most recents referenced directly on an embed could reduce read operation on the db.I learned about this pattern on the mongodb website here and here
The text was updated successfully, but these errors were encountered: