orm icon indicating copy to clipboard operation
orm copied to clipboard

Allow custom collections

Open guilhermeblanco opened this issue 8 years ago • 7 comments

guilhermeblanco avatar Sep 02 '17 18:09 guilhermeblanco

It would be nice to have this feature

sergiolatostadora avatar Jan 07 '19 21:01 sergiolatostadora

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?

Ocramius avatar Aug 24 '19 12:08 Ocramius

+1

wajdijurry avatar May 03 '20 00:05 wajdijurry

@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.

oojacoboo avatar Nov 24 '20 19:11 oojacoboo

I can't believe no one else wants custom methods on their Doctrine ORM collections - really baffles me.

oojacoboo avatar Jan 10 '25 05:01 oojacoboo

There are 9 upvotes to your previous message, why are you saying no one else wants this?

greg0ire avatar Jan 10 '25 12:01 greg0ire

@oojacoboo Why not contribute the changes?

ruudk avatar Jan 10 '25 12:01 ruudk