![](/img/trans.png)
[英]Symfony2 and Doctrine: proxy class does not lazy load entity fields
[英]Symfony 2 / Doctrine does not load associated entity
我在学说上有问题,并且无法懒惰地加载一对多/多对一双向绑定。
跟踪方案(仅必要的部分):
两张桌子:
Configuration:
type: entity
table: configuration
id:
idconfiguration:
type: integer
nullable: false
unsigned: false
comment: ''
id: true
generator:
strategy: IDENTITY
fields:
fkbasemodel:
type: integer
nullable: false
unsigned: false
comment: ''
manyToOne:
basemodel:
targetEntity: Basemodel
inversedBy: configurations
joinColumn:
name: fkbasemodel
referencedColumnName: idbasemodel
配置yaml的完整代码: http : //pastebin.com/v0G8TYqQ
和
Basemodel:
type: entity
table: basemodel
id:
idbasemodel:
type: integer
nullable: false
unsigned: false
comment: ''
id: true
generator:
strategy: IDENTITY
oneToMany:
configurations:
targetEntity: Configuration
mappedBy: basemodel
Basemodel Yaml的完整代码: http ://pastebin.com/2aBRNF1g
跟踪数据库条目:
Basemodel-表:
+-------------+
| idbasemodel |
+-------------+
| 1 |
| 2 |
+-------------+
配置 - 表:
+-----------------+-------------+
| idconfiguration | fkbasemodel |
+-----------------+-------------+
| 1 | 1 |
| 2 | 1 |
+-----------------+-------------+
配置类: http : //pastebin.com/sWYgRpjr
基本模型类: http ://pastebin.com/yaiD8kCB
当我获取配置实体并调用“ getBasemodel()”时。 它始终返回null。 即使'getFkbasemodel()'返回正确的外键。
为什么不能解析为正确的Basemodel实体? 它与其他协会的工作方式相同。
编辑:
添加了Pastbin链接以获取完整代码
在完整版本的配置中,oneToMany / manyToOne有多个条目。 与其多次指定该键,不如将所有该类型的关系放在一个键内。 拥有这样的重复项会使yaml唯一选择最后一个(它们是映射(字典),因此每个键只能有一个条目-还请注意,虽然最后一个条目的拾取是发生的,但这不是定义的行为) 。
你有:
oneToMany:
configurations:
targetEntity: Configuration
mappedBy: basemodel
oneToMany:
offers:
targetEntity: Offer
mappedBy: basemodel
应该:
oneToMany:
configurations:
targetEntity: Configuration
mappedBy: basemodel
offers:
targetEntity: Offer
mappedBy: basemodel
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.