5
votes

I'm fetching data with a many-to-many relationship and I want to define acustom method. Is it possible (and how) to use something like:

$hotel = $entityManager->getRepository('Hotels')->findOneById(1);
$types = $hotel->getTypes(); //$types is instance of **Doctrine\ORM\PersistentCollection**
$types->myCustomFunction(); //do something
1
I don't want to use repository, becouse i need to work with many to many relationship only. I want to create something like $hotel->getTypes()->fetchPairs() - user1518183
sorry, i misread the question, you may want to checkout stackoverflow.com/questions/3691943/… though - max
Thank, I tried it, but this doesn't solve my problem. I need to call custom method on object which is instance of Doctrine\ORM\PersistentCollection (that i've got when I fetch many to many relationship). - user1518183

1 Answers

0
votes

It seems to be not implemented already.

See this Doctrine's JIRA issue : http://www.doctrine-project.org/jira/browse/DDC-547

Consider allowing custom PersistentCollection implementations

We should consider allowing the configuration of custom PersistentCollection implementations on a per-association basis. This could allow users to craft optimized (SQL) behavior for for some of their collections to improve performance without changing the domain model code.

For this, PersistentCollection needs to be designed for inheritance.