I am having a problem with my Yii installation where I am trying to get a fairly simple request, but I am not getting results that online tutorials say what I should get. I have two models that look something like this:
Rates:
class Pricing extends CActiveRecord { public static function model($className=__CLASS__) { return parent::model($className); } public function tableName() { return 'pricing'; } public function primaryKey(){ return 'ID'; } ... public function relations() {
and PricingRoutes:
class PricingRoutes extends CActiveRecord { public static function model($className=__CLASS__) { return parent::model($className); } public function tableName() { return 'pricing_routes'; } public function primaryKey(){ return 'ID'; } ... public function relations() {
Then in the controller we have:
$criteria = new CDbCriteria; $criteria->with = array('xpricing_routes'); $criteria->together=true; $pricing_records = Pricing::model()->findAll($criteria); $pricing_records_arr = CHtml::listData($pricing_records, 'id', 'name'); echo '<pre>'; print_r($pricing_records); print_r($pricing_record_arr); echo '</pre>';
As you probably already know, we have 2 tables called prices and prices. The pricing route table has a foreign key called ID_pricing, which is sent to the ID field in the price table. The pricing table has one record, and the pricing_routes table has 4 records, each of which has a primary key for one element in the pricing table in the ID_pricing field. Therefore, we should get 4 results in the query that we run, and when I run the query that Yii generates using AR, this is what I get.
The problem we are facing is that the $ pricing_records variable is an array that has only one pricing object. This object contains the data that we need, but are not really applicable. The $ pricing_records_arr variable is just an empty array. The documentation I found seems to suggest that we should get an array of pricing objects, each of which contains information from the pricing_routes table. We know that using AR may not be the best way to get this data, but we have reasons for it to work, so any ideas on how to do this will be greatly appreciated.
EDIT:
It turns out this turned out to be a misunderstanding of what I am returning. Comments on this issue gave me the information I need.
source share