Show unserialize field

I have table Post and in this table I have one field that used serialize.

I want get all data from table and then in the view use unserialize for this field but in $models this field is NULL. How can get this field with findAll or another method?

$models = Post::model()->findAll('status = :status',array('status'=>2,));

$models = Post::model()->findAll('status = ?',array(2));


$models = Post::model()->findAll(array('condition' => 'status =:status', 'params' => array(':status' => 2)));

okay another option

$models = Post::model()->findAllByAttributes(array('status' => 2));

Thank You!

which is better, findAll or findAllByAttributes?

findAllByAttributes is just syntactic sugar, under the hood both compile down to the same method call

here says that findAllByAttributes protects against sqlinjection, is that true?

I have another question.

Table Post relation with table2 and table2 relation with table3

In Post, I need get data from table3.

In Post model I wrote this relation:

'table2'=>array(self::BELONGS_TO, 'Table2', 'w_id')

In with(array()) I just add table2. How can get data from table3?

I try use join instead with(array()) but I don’t understand why join didn’t work.

Then I used query command and I just get data from Post and table1:

$model = Yii::app()->db->createCommand()

		->select('t.*, t2.*,t3.*')

		->from('post t')

		->leftJoin('table2 t2', 't.w_id =')

                ->leftJoin('table3 t3', 't2.y =')

		->where('status =:status', array(':status'=>2))


How can join 3 tables?

if Post is related to table2 and table2 is related to table2, than:

U already have relation from Post to table2 (‘table2’),

make relation from table2 to table 3 (for example ‘table3’)

Than once U get Post recordes U need U can just go trough relations:

$post->table2->table3 to get table3 data

Please write this

$model = Yii::app()->db->createCommand()

 ->select('t.*, t2.*,t3.*')

 ->from('post t')

 ->leftJoin('table2 t2', 't.w_id =')

 ->leftJoin('table3 t3', 't2.y =')

 ->where('status =:status', array(':status'=>2))


with find(array()) and use with(array())

$models = Post::model()->find(array('with'=>array('')))

This is solution:

In model for table2:

'VarName3'=>array(self::BELONGS_TO, 'VarName3', 'y'),

In Post model

'VarName2'=>array(self::BELONGS_TO, 'table2', 'w_id','with'=>'VarName3'),


$model = Post::model()->with()->find(array(

			'condition'=>'status =:status',


			'params' =>array(

				':status' => 2,



how about this

$model = Post::model()->with('VarName2')->findByAttributes(array('status' => 2));