I am having trouble creating relations on non-key fields. My issue is that all records from the 'HAS_MANY' table are being returned, rather than just the matching values specified in the 'on' section of the relation.
Table: customer
- id (PK)
- name
- reference_key
Table: visit
- id
- system_id
- reference_key
Model: Customer relations...
'visits'=>array(self::HAS_MANY, 'Visit', '', 'on'=>'reference_key=visits.reference_key'),
Model: Visit relations...
'customer'=>array(self::BELONGS_TO, 'Customer', 'reference_key'),
$dataSet = $data->visits(); // this all records from visit table instead of visits matching on the reference key.
foreach($dataSet as $visit){
echo 'visit key: '.$visit->reference_key.'; ';
}
Using 'alias' resolves the ambiguous column names issue. However, I'm getting non-matching results.
Any help is appreciated. Thanks.