Hello Yii Developers,
once again your help is needed.
DB-Server: MSSQL
I try to create relation mappings between 3 tables. Here’s the table structure:
result
------
result_id <- PK
result_rows
-----------
result_id <- FK
row_id <- FK
rows
----
id <- PK
field1
...
fieldN
What I try to achieve is the possibility to be able to query the tables the following way:
$all_rows = Result::model()->with('row_ids', 'row_ids.row')->findAll('t.result_id = ?', array(1));
I have specified the relations in the correspondig models the following way:
class Result {
public function relations() {
return array(
'row_ids'=>array(self::HAS_MANY, 'ResultRows', 'result_id'),
);
}
}
class ResultRows {
public function relations() {
return array(
// this one doesn't work at all
//'row'=>array(self::BELONGS_TO, 'Rows', 'id'),
'row'=>array(self::BELONGS_TO, 'Rows', '', 'joinType'=>'inner join', 'on'=>'row_id = row.id'),
);
}
}
The problem I have is that findAll() fails to fetch the data from the database even though the generated query is correct (checked it in the application.log file and tried it out in the SQL Management Studio)
I think that I have an understanding problem of how to provide the relation data correctly. Even debugging CActiveRecord didn’t help much as it’s quite complex…
I hope that some nice community members can help me with this issue.
Many thanks in advance,
Regards,
Yiingeneur