【发布时间】:2013-09-17 20:42:02
【问题描述】:
我正在使用 Symfony1.4 和 Doctrine1.2 创建子对象并在执行时打印它们。问题是我总是从第一个查询中获取子对象。
我有以下架构:
Parent:
id
name
Child:
id
parent_id
name
我的操作:
- 最初我有一个 父母(id=1)和没有 孩子
- 我获取了一个Parent (id=1) 并将该对象存储在
$parent - 列出它的子对象
- 结果:
noneOK:如预期的那样 - 创建一个新的Child并将其父级设置为
1 - 列出
$parent的子对象 - 结果:
none哎呀:我期待 5 岁的新孩子。!
代码:
$parent = Doctrine_Query::create()->from('Parent p')->where('p.id = ?', 1)->limit(1)->fetchOne(); /* from 2. */
print_r($parent->getChild()->toArray()); /* from 3. */
$child = new Child();
$child->setParentId($parent->getId());
$child->save(); /* from 4. */
print_r($parent->getChild()->toArray()); /* from 6. */
我已经尝试在最后一行之前重新抓取$parent,但结果是一样的。
【问题讨论】:
标签: php doctrine symfony-1.4 doctrine-1.2