I have a mysql table and a mysql view I’m trying to build relations for.
The table(commissions) is as follows:
--commissions--
id(primary Key)
date_added
order_id
salesrep_id
customer_id
commission_total
status
The view(rep_view_customer) is as follows:
--rep_view_customer--
entity_id
email
first_name
last_name
company
I’m trying to relate rep_view_customer to commissions on commissions.customer_id = rep_view_customer.entity_id.
I’ve tried using the on option:
'rep_view_customer' => array(self::HAS_ONE, 'RepViewCustomer', '', 'on'=>'rep_view_customer.entity_id = t.customer_id')
I also tried setting the primary key for the rep_view_customer model using:
public function primaryKey(){
return 'entity_id';
}
But I always seem to end up with an error similar to:
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]:
Column not found: 1054 Unknown column ‘t.customer_id’ in ‘where
clause’. The SQL statement executed was: SELECT
rep_view_customer.entity_idASt1_c0,
rep_view_customer.t1_c1,
rep_view_customer.first_nameASt1_c2,
rep_view_customer.last_nameASt1_c3,
rep_view_customer.companyASt1_c4FROMrep_view_customer
rep_view_customerWHERE (rep_view_customer.entity_id =
t.customer_id)
I’m at my wit’s end what to try next
You will have to create a foreign key inside repview_customer to relate to commissions. You won’t be able to do it with just a primary key.