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

or


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

http://www.yiiframework.com/wiki/275/how-to-write-secure-yii-applications/#hh11

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 = t2.id')

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

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

		->queryRow();

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 = t2.id')

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

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

 ->queryRow();

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'),

Controler:


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

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

			'with'=>array('VarName2'),

			'params' =>array(

				':status' => 2,

				),

			));

how about this


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