الثلاثاء، 24 ديسمبر 2013

yii cdbcriteria->with child table record not displayed in view

In yii based application Im working on a search query. query is performed on two tables customers and customerContacts. Customer can have one-to-many contacts in different countries

Im using cdbcriteria as:

$criteria = new CDbCriteria;$criteria->alias = 't' ;$criteria->with= array("customerContacts"=> array("select"=>"customerContacts.fullname")); $criteria->condition = " customerContacts.country_id = 1";$customers = Customer::model()->findAll($criteria);

Relations are

In Costumer model:

'customerContacts' => array(self::HAS_MANY, 'customerContacts', 'customer_id'),

in customerContact model:

'customer' => array(self::BELONGS_TO, 'Customer', 'customer_id'),

Issue is that there is a fullname column in customerContact table. This cdbCriteria is picking that fullname but it is not displayed that in view page, although data exists in table.

view code

customerContacts->fullname;endforeach; ?>

I'am stuck in this. please help where im doing wrong?


View the original article here

ليست هناك تعليقات:

إرسال تعليق