how to load model with findAll and return model

Hello master … i have code like this







	public function loadWarehouseStock($wid,$pid)

	{

		$models=WarehouseStock::model()->findAll(array(

			'condition'=>'warehouse_id=:vwid AND product_id=:vpid',

			'params'=>array(':vwid'=>$wid, ':vpid'=>$pid),

		));

		

		$stock_id=0;

		if($models!=null)

		{

			foreach($models as $model)

				$stock_id=$model->id;

		}

		$stock=WarehouseStock::model()->findByPk($stock_id);

		return $stock;

	}



the problem i can’t get stock becouse the return value is array. how I will get $stock as WarehouseStock, and create new value then i will update the value of stock…

Umm … I don’t quite follow your logic. Why do you use findAll() and then get the last one (again) with findByPK()?

Can’t you just use findByAttributes()?

Ok thank … i have found the solve… I read doc … i use find(),

thank for respond