Doctrine join查询访问问题
我有两个表 page 和 page_desc ,并且有一个关系
$this->hasMany('Model_PagesDesc as PageDesc', array( '本地' => 'ID', '外国' => 'pages_id'));
我
return Doctrine_Query::create()
->select('m.*, d.*')
->from('Model_Pages m')
->leftJoin('m.PageDesc d')
->execute();
现在有一个查询,当查询执行时。在视图中,当我尝试获取第二个表的字段值时,它返回一些整数而不是字段中的实际值
<?php echo $pages->PageDesc->content;?>
i have two tables pages and page_desc and have a relation
$this->hasMany('Model_PagesDesc as PageDesc', array(
'local' => 'id',
'foreign' => 'pages_id'));
i have a query
return Doctrine_Query::create()
->select('m.*, d.*')
->from('Model_Pages m')
->leftJoin('m.PageDesc d')
->execute();
NOW WHEN QUERY EXECUTES. iN VIEW WHEN I TRY TO GET FIELD VALUE OF SCEOND TABLE IT RETURNS SOME INTEGER INSTEAD OF ACUAL VALUE IN FIELD
<?php echo $pages->PageDesc->content;?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是
hasMany
,那么您的Model_Pages::PagesDesc
应该是一个Doctrine_Collection
而不是Model_PagesDesc
实例。我不确定,但我假设集合的默认行为是在转换为字符串时返回集合中元素的计数,即整数。您需要循环遍历集合或获取特定项目。或者
或者您可以为此模型编写一个自定义集合,该集合返回集合中每个元素的
content
字段的串联。然而,似乎一个页面实际上不应该有多个描述,不是吗?您可能需要考虑使用 1-1 关系或仅将描述作为页面模型上的列。
If youre using
hasMany
then you shouldModel_Pages::PagesDesc
will be aDoctrine_Collection
not aModel_PagesDesc
instance. Im not sure but i would assume that the default behavior of the collection is to return thecount
of elements in the collection when converted to string, thus the integer. You need to either loop over the collection or get a specific item.OR
Or you could write a custom collection for this model that returns concat of the
content
fields for every element in the collection.However it seemdsthat a page shouldnt really have more than one description should it? You might want to consider using a 1-1 relation or just making the description a column on your page model.