2011-10-15 21 views
3

我有一個MappedSuperclass抽象類(AbstractImage),其他兩個實體從它繼承(UrlImageUploadImage)。在Doctrine 2(.1)中 - 我可以擁有MappedSuperclass實體的(虛擬)存儲庫嗎?

超有關聯到其他實體(Post),我需要一種方式來獲得和往返於Post實體自動(設置UrlImageUploadImage的實例=這意味着我必須在一個addImagePost實體,它將知道給定實體是否爲UploadImageUrlImage實體)。

同樣,由於每個實體都有自己的id的記錄,我需要,將有一個find方法,該方法將得到idtypeurlupload)虛擬存儲庫,並調用find方法上相應的庫(UploadImageRepositoryUrlImageRepository)。

獲得正常的庫(如UrlImageRepository)很簡單:

$em->getRepository('UrlImage'); 

,但我怎麼能做到這一點對MappedSuperclass

以下是關於形勢的一些詳細信息:How can I do complex entity associations queries in doctrine 2? (virtual entity)

回答

0

還沒有嘗試過,但你可以嘗試做3個庫和製作UploadImageRepositoryUrlImageRepository延長三分之一(基地,虛擬)庫。

Btw。對MappedSuperclasses的一些建議......總是抽象出來,否則你會遇到各種各樣的其他錯誤。

0

僅供參考。可以爲AbstractImage加載存儲庫,因此find方法適用於每個繼承實體:

$imageRepository = $entityManager->getRepository('MyBundle:AbstractImage'); 
$urlImage = $imageRepository->find(1); //assuming record with id=1 is UrlImage entity 
$uploadImage = $imageRepository->find(2); //assuming record with id=2 is UploadImage entity 
相關問題