开发者

Doctrine join query access problem

开发者 https://www.devze.com 2023-03-16 03:39 出处:网络
i have two tables pages and page_desc and have a relation $this->hasMany(\'Model_PagesDesc as PageDesc\', array(

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')
                 ->execu开发者_如何学JAVAte();

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;?>


If youre using hasMany then you should Model_Pages::PagesDesc will be a Doctrine_Collection not a Model_PagesDesc instance. Im not sure but i would assume that the default behavior of the collection is to return the count 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.

<?php echo $pages->PageDesc->getFirst()->content; ?>

OR

<?php foreach($pages->PageDesc as $desc): ?>
  <?php echo $desc->content; ?>
<?php endforeach; ?>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消