2012-10-02 33 views
5

我使用多對多關係獲取數據,我想定義acustom方法。是否有可能(以及如何)使用類似的東西:在Doctrine ORM PersistentCollection中定義自定義方法

$hotel = $entityManager->getRepository('Hotels')->findOneById(1); 
$types = $hotel->getTypes(); //$types is instance of **Doctrine\ORM\PersistentCollection** 
$types->myCustomFunction(); //do something 
+0

我不想使用存儲庫,因爲我需要使用多對多的關係而已。我想創建類似'$ hotel-> getTypes() - > fetchPair()' – user1518183

+0

對不起,我誤解了這個問題,你可能想結賬http://stackoverflow.com/questions/3691943/custom-collection-in -doctrine2雖然 – max

+0

謝謝,我試過了,但這並不能解決我的問題。我需要調用Doctrine \ ORM \ PersistentCollection實例的對象上的自定義方法(當我獲取多對多關係時,我得到了這個方法)。 – user1518183

回答

0

它似乎還沒有實現。

請參見本主義的JIRA問題:http://www.doctrine-project.org/jira/browse/DDC-547

考慮允許自定義PersistentCollection實現

我們應該考慮允許在每個協會基礎上定製PersistentCollection實現的配置。 這可以允許用戶爲其某些集合制定優化(SQL)行爲,以提高性能,而無需更改域模型代碼。

爲此,PersistentCollection需要設計用於繼承。

+0

請改善您的答案.. – 5ervant

相關問題