在Doctrine中使用不同的模式

时间:2015-04-07 19:11:20

标签: oracle symfony doctrine-orm oracle11g doctrine

我正在使用doctrine2和oracle。有几个模式schema1和schema2。当我创建一个包含以下内容的表单时

// ....
public function buildForm(FormBuilderInterface $builder, array $options)
{
    // ....
    $builder
        ->add('userPartner', 'entity', array(
                'class' => 'SoftclubTopbyBundle:Party',
                'property' => 'legalName',
                'placeholder' => '',
                'multiple' => true,
        ))
    ;
    // ....
}
//...

symfony引发了一个例外:

MappingException in MappingException.php line 37:
The class 'Softclub\TopbyBundle\Entity\Nsi\NsiChainStore' was not found in
the chain configured namespaces Softclub\TopbyBundle\Entity\Topby

我在config.yml中有以下设置

entity_managers:
    default:
        connection: default
        mappings:
            SoftclubTopbyBundle: { type: yml, dir: Resources/config/doctrine/topby, prefix: Softclub\TopbyBundle\Entity\Topby }
    nsi:
        connection: nsi
        mappings:
            SoftclubTopbyBundle: { type: yml, dir: Resources/config/doctrine/nsi, prefix: Softclub\TopbyBundle\Entity\Nsi }

以及两个实体之间的以下关系

Softclub\TopbyBundle\Entity\Topby\Party:
    manyToOne:
        chainStore:
            targetEntity: Softclub\TopbyBundle\Entity\Nsi\NsiChainStore
            cascade: {  }
            mappedBy: null
            inversedBy: null
            joinColumns:
                CHAIN_STORE_ID:
                    referencedColumnName: ID
            orphanRemoval: false

我能做错什么?

2 个答案:

答案 0 :(得分:1)

谢谢大家的答案。正如Matteo所说,实体被放在一个单独的捆绑中。问题解决如下

default:
    connection: default
    mappings:
        SoftclubTopbyBundle: ~
        SoftclubNsiBundle: ~

# for generate entities
topby:
    connection: default
    mappings:
        SoftclubTopbyBundle: ~
nsi:
    connection: nsi
    mappings:
        SoftclubNsiBundle: ~

答案 1 :(得分:0)

你不能通过不同的联系建立学说关系。您可以使用事件侦听器来实现此目的。 例如,一个实体(比如Note)有一些属性,它引用属于另一个实体管理器(连接)的另一个实体(比如User)。 Note实体将用户的ID保留为外键。 每当加载Note对象时,事件侦听器都会使用它的ID来实例化User对象(postLoad事件)。

http://symfony.com/doc/current/cookbook/doctrine/event_listeners_subscribers.html

主义事件: http://doctrine-orm.readthedocs.org/en/latest/reference/events.html#lifecycle-events

关于表单,如果'userPartner'映射到该连接,则将选项实体管理器与'nsi'放在一起。

'em'=>'nsi'

没有与Oracle合作,希望这有帮助。

相关问题