2012-02-17 112 views
0

編輯:問題從不同的包實體使用不同的實體管理器

我準備這一次解壓縮並運行./bin/vendors後安裝一個tar.gz無法通過PHP腳本/ createAll加載裝置。 PHP。在tar.gz中,有兩個捆綁使用兩個不同的連接,每個人都有自己的數據庫。

我認爲Symfony2無法正確管理它們。如果你看看scripts/createAll.php將會看到symfony如何加載兩個燈具,但是如果你刪除了一個隨機燈具(這並不重要Var_.php或Foo_.php一切運行良好,這在我看來symfony中未能正確地管理實體)

LINK:http://www.2shared.com/file/2u4GhFVX/SymfonyTestCasetar.html

我想告訴Symfony2使用不同entity managers針對不同Bundle directories所以我config.yml樣子:

orm: 
    auto_generate_proxy_classes: %kernel.debug% 
    default_entity_manager: default 
    entity_managers: 
     default: 
      connection: default 
      mappings: 
       myVendorURLCoreBundle: ~ 
       myVendormyBundleBundle: ~ 
       myVendormyBundleFooBundle: 
        prefix: "myVendor\myBundleFooBundle\Entity" 
        type: annotation 
        is_bundle: true 
        dir: "/Entity" 
     formacions: 
      connection: formacions 
      mappings: 
       myVendormyBundleFooBarBundle: 
        prefix: "myVendor\myBundleFooBarBundle\View" 
        type: annotation 
        is_bundle: false 
        dir: "%kernel.root_dir%/../src/myVendor/myBundleFooBarBundle/View" 

的問題是當使用不同di中的實體之間的關係時累託石,我得到以下因素導致錯誤的vendor/doctrine/lib/Doctrine/ORM/Mapping/MappingException.php at line 142

Class FRJPC\SalleUrlFormacionsBundle\Entity\EspecialitatContingut is not a valid entity or mapped super class

的probem是,有時「\」供應商名稱之前中斷的命名空間。這真的很奇怪。

這是我如何我彼此之間鏈接的實體:

 


namespace myVendor\myBundleFooBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* @ORM\Entity(repositoryClass="myVendor\myBundleFooBundle\Repository\ARepository") 
* @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT") 
* @ORM\Table(name="a") 
*/ 
class A 
{ 
    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer", length="4") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    private $id; 

    /** 
    * @ORM\ManyToOne(targetEntity="\myVendor\myBundleFooBarBundle\Entity\B", inversedBy="a", cascade={"persist"}) 
    * @ORM\JoinColumn(name="FooBar", nullable=true, referencedColumnName="FooBar", onDelete="CASCADE") 
    */ 
    private $fooBar; 
} 

二實體:

 

namespace myVendor\myBundleFooBarBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* @ORM\Entity(repositoryClass="myVendor\myBundleFooBarBundle\Repository\ARepository") 
* @ORM\ChangeTrackingPolicy("DEFERRED_EXPLICIT") 
* @ORM\Table(name="a") 
*/ 
class B 
{ 
    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer", length="4") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    private $id; 

     /** @ORM\OneToMany(targetEntity="\myVendor\myBundleFooBundle\Entity\EspecialitatContingut", mappedBy="fooBar") */ 
     private $a; 
} 

沒有任何一個對我應該怎麼每個實體鏈接線索?

PD:兩個實體在相同的包和相同的目錄中時都像魅力一樣工作。

回答

3

所有這些Foos和Bars結合一個帶有真實姓名的錯誤信息使其有點難以遵循,並且使得發佈的代碼實際上與實際代碼不匹配的可能性變得有些困難。 FooBarBundle/View似乎不太適合存儲實體。

無論如何,像formacions這樣的特定實體經理需要能夠看到所有相關實體,包括那些涉及到關係的實體。它看起來像你在foo包中定義了A和在條包中定義了B,並且它們都相互交叉引用?

從您的配置中,我看不到formacion em如何看到您的A實體,同樣我也看不到默認em可以看到B實體。關係中的全限定類名不足以共享實體原則元數據。因此錯誤信息。

我真的很高興能證明這個錯誤。不能做這些事情有點令人沮喪。

+0

非常感謝您的回答。據我瞭解,在confyg.yml中,我定義了不同的實體管理器,這些實體管理器由不同的bundle使用,並且只有在關係中使用FQDN時才相互瞭解,這種概念是否錯誤?我要上傳一個測試案例,所以如果你有時間的話,你可以看看它。非常感謝您的時間,我真的很關心如何解決這個問題。 – user846226 2012-02-18 09:09:37

+0

你可能想看看這個:http://stackoverflow.com/q/9311485/1146363命令:app/console doctrine:mapping:info --em EntityManagerName可以給你一些關於到底給定實體管理器可以看到。 – Cerad 2012-02-18 17:04:57

+0

非常感謝您的回答。我確實知道pp/console主義:mapping:info --em ='foo'命令,但不知道它如何提供幫助。我認爲symfony在管理多個連接時存在一些問題,因爲實體很好,也有固定裝置,並且只有一個固定裝置存在時它們可以毫無問題地加載。 – user846226 2012-02-19 13:17:14