Get Value From Has Many Relation

Hi All

I had problem to load value from has many relations

this is my tables :

My target is print gallery name with one image related to gallery

gallery model




 	* @return array relational rules.

	 */

	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'event' => array(self::BELONGS_TO, 'Events', 'event_id'),

			'course' => array(self::BELONGS_TO, 'Courses', 'course_id'),

			'images' => array(self::HAS_MANY, 'Images', 'gal_id'),

			'releatedtrs' => array(self::HAS_MANY, 'Releatedtr', 'gal_id'),

		);

	}



how to call one image , is it possible to write like this ?




$gallerymodel=gallery::model()->findAll();


foreach(gallerymodel as $value ){


 echo $value->images->image;

}




Thanks in advance

No, you’d do this:




    if (count($value->images))

        echo $value->images[0]->image; // Access first image



Thank u Keith