orm
orm copied to clipboard
Allow custom collections
It would be nice to have this feature
Note that https://github.com/doctrine/collections/pull/177 alleviates the need for this massively. @guilhermeblanco given the complexity of this feature (and the implications of added inheritance support), would you be willing to drop this from 3.x?
+1
@Ocramius I'm not sure how the need for custom collections is alleviated by generics psalm support. Can you please elaborate on that one.
Custom collections are a good idea for when your ORM is returning a collection and you want to include custom logic into that value holder. This can be very useful in many business logic use cases. For instance, you might have something like the following:
$bars = $foo->getBars();
$latestBar = $bars->orderBy('date', 'desc')->first();
In the example above, we've simply added an orderBy method into our custom Collection class that takes a property argument and orders the results based on that. By using a fluid interface, we can chain additional methods. Further, if we leverage a php port of C#'s LINQ, like https://github.com/Athari/YaLinqo, we're able to perform a lot of really awesome data parsing directly within our collections.
I can't believe no one else wants custom methods on their Doctrine ORM collections - really baffles me.
There are 9 upvotes to your previous message, why are you saying no one else wants this?
@oojacoboo Why not contribute the changes?