在 Doctrine 中使用不同的模式
Work with different schemas in Doctrine
我在 oracle 中使用 doctrine2。有几个模式 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
我做错了什么?
你不能在不同的连接上建立学说关系。您可以为此目的使用事件侦听器。
例如,一个实体(比如 Note)有一些 属性 是对属于另一个实体管理器(连接)的另一个实体(比如 User)的引用。 Note 实体将用户 ID 作为外键保存。
事件侦听器用于在加载 Note 对象(postLoad 事件)时使用它的 ID 来实例化 User 对象。
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,希望对您有所帮助。
谢谢大家的回答。正如 Matteo 所说,这些实体被放在一个单独的包中。问题解决如下
default:
connection: default
mappings:
SoftclubTopbyBundle: ~
SoftclubNsiBundle: ~
# for generate entities
topby:
connection: default
mappings:
SoftclubTopbyBundle: ~
nsi:
connection: nsi
mappings:
SoftclubNsiBundle: ~
我在 oracle 中使用 doctrine2。有几个模式 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
我做错了什么?
你不能在不同的连接上建立学说关系。您可以为此目的使用事件侦听器。 例如,一个实体(比如 Note)有一些 属性 是对属于另一个实体管理器(连接)的另一个实体(比如 User)的引用。 Note 实体将用户 ID 作为外键保存。 事件侦听器用于在加载 Note 对象(postLoad 事件)时使用它的 ID 来实例化 User 对象。
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,希望对您有所帮助。
谢谢大家的回答。正如 Matteo 所说,这些实体被放在一个单独的包中。问题解决如下
default:
connection: default
mappings:
SoftclubTopbyBundle: ~
SoftclubNsiBundle: ~
# for generate entities
topby:
connection: default
mappings:
SoftclubTopbyBundle: ~
nsi:
connection: nsi
mappings:
SoftclubNsiBundle: ~