I'm having trouble getting Cake to join on the correct foreign keys. Below is the current SQL that Cake produces.
SELECT
"AirtimeShowInstance"."id" AS "AirtimeShowInstance__id",
"AirtimeShowInstance"."starts" AS "AirtimeShowInstance__starts",
"AirtimeShowInstance"."ends" AS "AirtimeShowInstance__ends",
"AirtimeShowInstance"."show_id" AS "AirtimeShowInstance__show_id",
...
"AirtimeShow"."id" AS "AirtimeShow__id",
...
FROM
"public"."cc_show_instances" AS "AirtimeShowInstance"
LEFT JOIN
"public"."cc_show" AS "AirtimeShow"
ON (
"AirtimeShow"."id" = "AirtimeShowInstance"."id"
)
WHERE
1 = 1
ORDER BY
"AirtimeShowInstance"."starts" DESC
If I change the join parameter manually from
("AirtimeShow"."id" = "AirtimeShowInstance"."id")
to
("AirtimeShow"."id" = "AirtimeShowInstance"."show_id")
it works fantastically!
What's wrong with my Models? :(
AirtimeShowInstance.php
class AirtimeShowInstance extends AppModel {
public $useTable = 'cc_show_instances';
public $hasOne = array('AirtimeShow' => array(
'className' => 'AirtimeShow',
'foreignKey' => 'id'
));
}
AirtimeShow.php
class AirtimeShow extends AppModel {
public $useTable = 'cc_show';
public $hasMany = array('AirtimeShowInstance' => array(
'className' => 'AirtimeShowInstance',
'foreignKey' => 'show_id'
));
}