Yii Framework Forum: SQL function in SELECT - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

SQL function in SELECT GROUP_CONCAT Rate Topic: -----

#1 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 28 October 2009 - 04:38 PM

i'm still trying to get the GROUP_CONCAT function working. but <?php echo $daytrip->rTag->gTags; ?> remains empty.

hope you can help me out?

model Daytrip:
    public function relations()
    {
        return array(
            'rCity' => array(self::BELONGS_TO, 'City', 'CityId'),
            'rTag' => array(self::MANY_MANY, 'Tag', 'DaytripTag(DaytripId, TagId)', 
                'select' => array('GROUP_CONCAT(Tag) AS gTags')),
        );
    }


view Daytrip:
<tr valign="top">
    <td><?php echo $daytrip->IdDaytrip; ?></td>
    <td><?php echo $daytrip->Daytrip; ?></td>
    <td><?php echo $daytrip->rCity->City; ?></td>
    <td>-<?php echo $daytrip->rTag->gTags; ?>-</td>
    <td><?php echo date('j M Y', strtotime($daytrip->Modified)); ?></td>
</tr>


controller Daytrip:
$daytrips = Daytrip::model()->with('rCity', 'rTag')->findAll($criteria);

0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,892
  • Joined: 04-October 08
  • Location:DC, USA

Posted 28 October 2009 - 04:43 PM

Since it is MANY_MANY relation, rTag should be an array.
0

#3 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 28 October 2009 - 04:47 PM

View Postqiang, on 28 October 2009 - 04:43 PM, said:

Since it is MANY_MANY relation, rTag should be an array.


sorry don't get it. i thougt because of the GROUP_CONCAT i get a string "tag1, tag2, tag3" in the variable $daytrip->rTag->gTags.

where can i find that string?
0

#4 User is offline   tri 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,651
  • Joined: 20-November 08
  • Location:Stockholm, Sweden

Posted 28 October 2009 - 09:24 PM

View Postbas_vdl, on 28 October 2009 - 04:47 PM, said:

sorry don't get it. i thougt because of the GROUP_CONCAT i get a string "tag1, tag2, tag3" in the variable $daytrip->rTag->gTags.

where can i find that string?


$daytrip->rTag[$i]->gTags


BTW I noticed it's possible to write something like "$daytrip->rTag->anything" with no error message.

/Tommy
Don't forget to read The Definitive Guide to Yii (en) (sv) | The class reference has the details
0

#5 User is offline   bas_vdl 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 215
  • Joined: 01-April 09

Posted 29 October 2009 - 04:47 AM

View Posttri, on 28 October 2009 - 09:24 PM, said:

$daytrip->rTag[$i]->gTags


BTW I noticed it's possible to write something like "$daytrip->rTag->anything" with no error message.

/Tommy


Great, thank you!

in the view: <?php echo $daytrip->rTag2[0]->gTags; ?>

and in de model i added 'group' => 'IdDaytrip' to the realtion.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users