Hey everyone.
I created 2 Models. "Resource" and "ResourceType" (these 2 Model.php files are attached).
They both have a Relation to “company” array(self::BELONGS_TO, ‘Company’, ‘company_id’).
So, now i want select all resources I have also filled with the ResourceType. To get all the Resources, I must refer to company_id, but it’s enough if only the resource refers to the company-table.
Here my Statement-Preparation:
$criteria = new CDbCriteria;
$criteria->with = array(
'resourceType',
);
$criteria->condition = 'company_id=:companyID';
$criteria->params = array(':companyID' => 1);
$criteria->order = "resource_type_id ASC";
$resources = Resource::model()->findAll($criteria);
But not i get a "CDbException"
CDbException
CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'company_id' in where clause is ambiguous
Here you got also my Application LOG
05:15:10.093853 error system.db.CDbCommand
Error in querying SQL: SELECT `t`.`id` AS `t0_c0`, `t`.`name` AS `t0_c1`,
`t`.`email` AS `t0_c2`, `t`.`company_id` AS `t0_c3`, `t`.`resource_type_id`
AS `t0_c4`, `resourceType`.`id` AS `t1_c0`, `resourceType`.`name` AS
`t1_c1`, `resourceType`.`order` AS `t1_c2`, `resourceType`.`company_id` AS
`t1_c3` FROM `resource` `t` LEFT OUTER JOIN `resource_type` `resourceType`
ON (`t`.`resource_type_id`=`resourceType`.`id`) WHERE
(company_id=:companyID) ORDER BY resource_type_id ASC
That’s not clear to me, I think i made everything right. Is it a bug?
Thank you very much!
At the bottomline: if I change company_id to company_idd in the ResourceType Model (and DB) it works.