Allow custom collections #5671

Open
opened 2026-01-22 15:14:13 +01:00 by admin · 7 comments
Owner

Originally created by @guilhermeblanco on GitHub (Sep 2, 2017).

Originally created by @guilhermeblanco on GitHub (Sep 2, 2017).
Author
Owner

@sergiolatostadora commented on GitHub (Jan 7, 2019):

It would be nice to have this feature

@sergiolatostadora commented on GitHub (Jan 7, 2019): It would be nice to have this feature
Author
Owner

@Ocramius commented on GitHub (Aug 24, 2019):

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 commented on GitHub (Aug 24, 2019): 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`?
Author
Owner

@wajdijurry commented on GitHub (May 3, 2020):

+1

@wajdijurry commented on GitHub (May 3, 2020): +1
Author
Owner

@oojacoboo commented on GitHub (Nov 24, 2020):

@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 commented on GitHub (Nov 24, 2020): @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.
Author
Owner

@oojacoboo commented on GitHub (Jan 10, 2025):

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

@oojacoboo commented on GitHub (Jan 10, 2025): I can't believe no one else wants custom methods on their Doctrine ORM collections - really baffles me.
Author
Owner

@greg0ire commented on GitHub (Jan 10, 2025):

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

@greg0ire commented on GitHub (Jan 10, 2025): There are 9 upvotes to your previous message, why are you saying no one else wants this?
Author
Owner

@ruudk commented on GitHub (Jan 10, 2025):

@oojacoboo Why not contribute the changes?

@ruudk commented on GitHub (Jan 10, 2025): @oojacoboo Why not contribute the changes?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5671