[英]Doctrine query in Symfony 1.4, not sure what I am doing wrong here
I have a query that reads like this:我有一个查询,内容如下:
$fields = Doctrine_Core::getTable('model_1')->findByColumnId($id);
took a var_dump on fields, and it retrieves data as it should;在字段上进行了 var_dump,并按应有的方式检索数据;
next up, I do this接下来,我这样做
foreach($fields as $field)
{
$newerFields[$field->getColumnId()] =
Doctrine_Core::getTable('model2')->findByColumn2Id($field->getColumnId());
}
I take a var_dump on each $newerFields[$field] and it does yield the result as it should.我对每个 $newerFields[$field] 进行了 var_dump,它确实产生了它应该产生的结果。 Next up I try and do this:
接下来我尝试这样做:
foreach($newerFields as $newerField)
{
echo $newerField->getColumn3();
}
But this spits out: Call to undefined method Doctrine_Collection::getColumn3() in actions.class.php on line 69但这吐出:在第 69 行的 actions.class.php 中调用未定义的方法 Doctrine_Collection::getColumn3()
I am not able to wrap my head around this and am flustered thinking on how to get it done.我无法全神贯注地思考如何完成它。 Can anyone spot the trouble for me?
谁能帮我找出问题所在?
Your findByColumn2Id
returns a Doctrine_Collection because findBy
always returns a collection (if you don't define it in the table file) even if there is only one result.你的
findByColumn2Id
返回一个 Doctrine_Collection 因为findBy
总是返回一个集合(如果你没有在表文件中定义它)即使只有一个结果。 If you want to retrieve one result, use findOneBy
instead.如果要检索一个结果,请改用
findOneBy
。
Otherwise, you will have to loop on newerFields
childs to retrieve data:否则,您将不得不循环访问
newerFields
来检索数据:
// array of Doctrine_Collection
foreach($newerFields as $newerFieldCollection)
{
foreach($newerFieldCollection as $newerField)
{
echo $newerField->getColumn3();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.