get limit 1 from one to many Relational Active Record

i want to get relational query only one row from this table


album

===========

id

title



pic

===========

id

album_id

photo

create_time


my Relation


	public function relations()

	{

		return array(

			'albumPics' => array(self::HAS_MANY, 'Pic', 'album_id'),

			'albumcount' => array(self::STAT, 'Pic', 'album_id'),

			'albumfoto' => array(self::HAS_MANY, 'Pic','album_id', 'order'=>'create_time ASC', 'limit'=>'1'),

		);

	}



Problem Output here…

album.id

album.title

albumcount count from pic where album.id = pic.album_id

albumphoto get only one photo column from pic where album.id = pic.album_id order by create_time ASC limit 1

my index _view


<?php echo CHtml::encode($data->id); ?>

<?php echo CHtml::encode($data->title); ?>

<?php echo CHtml::encode($data->albumcount); ?>

<?php echo CHtml::encode($data->albumfoto); ?> --> error



Error


if using 'albumfoto' => array(self::HAS_ONE, 'Pic','album_id', 'order'=>'create_time ASC', 'limit'=>'1'),

error : Property "CHasOneRelation.limit" is not defined.


if using 'albumfoto' => array(self::HAS_MANY, 'Pic','album_id', 'order'=>'create_time ASC', 'limit'=>'1'),

error : htmlspecialchars() expects parameter 1 to be string, array given

Anyone can help… can i use relations for get photo column ?

thanks before

solve it…

relation


public function relations()

{

return array(

'albumPics' => array(self::HAS_MANY, 'Pic', 'album_id'),

'albumcount' => array(self::STAT, 'Pic', 'album_id'),

'albumfoto' => array(self::HAS_MANY, 'Pic','album_id', 'order'=>'create_time ASC', 'limit'=>'1'),

);

}



View


<?php echo CHtml::encode($data->id); ?>

<?php echo CHtml::encode($data->title); ?>

<?php echo CHtml::encode($data->albumcount); ?>

<?php foreach($data->albumFoto as $aFoto) echo $aFoto->foto; ?>

Hi,

Am having the same problem

I want to fetch a record in 1:n relation

i have defined the relation as below to fetch the recent status date

‘ITEM_HAS_MANY_ITEMSTATUS’ => array(self::HAS_MANY, ‘ItemStatus’, ‘itemId’, ‘group’ => ‘ITEM_HAS_MANY_ITEMSTATUS.itemId’, ‘order’ => ‘statusDate DESC’, ‘limit’ => 1),

it gives me wrong answer. can anyone help me on how to solve it?