Hi all,
Newbie here.
I have three tables: tbl_facility, tbl_type, tbl_facility_type, you can tell that Facility and Type is many to many relation. tbl_facility_type has only two columns (type_id, facility_id), which makes the composite PK.
In model Facility, relations:
‘types’=>array(self::MANY_MANY, ‘Type’, ‘tbl_facility_type(facility_id, type_id)’),
In model Type, relations:
‘facilities’=>array(self::MANY_MANY, ‘Facility’, ‘tbl_facility_type(type_id,facility_id)’),
Now, I am trying to write an API that query certain[offset: 0, limit=10] facilities: Each facility has (type_id=1) as one of its Types. And, during the query, I only want to select tbl_facility.id, tbl_facility.name.
Here is the code I am working on:
$type=Type::model()->findByPk($_GET[‘type’]);
$models=$type->facilities(array(
'offset'=>$_GET['offset'],
'limit'=>$_GET['limit'],
'select'=>array('id', 'name'),
));
It does not work. Could anyone point me to the right direction? Thanks a lot.