Maybe I am just having a slow day, but for the life of me I can't figure out why this is happening. I haven't done CakePHP in a while and I am trying to use the 1.3 version, but this doesn't seem to be working...
I have two models:
area.php
<?php
class Area extends AppModel {
var $name = 'Area';
var $useTable = 'OR_AREA';
var $primaryKey = 'A_ID';
var $belongsTo = array(
'Building' => array(
'className' => 'Building',
'foreignKey' => 'FK_B_ID',
),
'Facility' => array(
'className' => 'Facility',
'foreignKey' => 'FK_F_ID',
),
'System' => array(
'className' => 'System',
'foreignKey' => 'FK_S_ID',
)
);
}
?>
building.php
<?php
class Building extends AppModel {
var $name = 'Building';
var $useTable = 'OR_BLDG';
var $primaryKey = 'B_ID';
var $hasMany = array(
'Area' => array(
'className' => 'Area',
'foreignKey' => 'FK_B_ID',
)
);
}
?>
OR_AREA
has a column titled FK_B_ID
that refers to the B_ID
.
If I run something like:
$this->Building->find('all', array('recursive' => 2));
I get empty [Area]
arrays for all the Buildings even though there are plenty of Areas in the OR_AREA
table that are associated to buildings. Not only that, the Query Table doesn't even show CakePHP attempted to find anything but all the records in OR_BLDG
. All the more puzzling, if I do:
$this->Area->find('all');
I get all the Areas and the [Building]
arrays are populated when appropriate.
What am I missing?
Edit:
The relevant parts of my schema:
CREATE TABLE ORDB_ADMIN.OR_AREA
(
A_ID NUMBER(8),
NAME VARCHAR2(255 BYTE) NOT NULL,
FK_F_ID NUMBER(8),
FK_S_ID NUMBER(8),
FK_B_ID NUMBER(8)
)
CREATE TABLE ORDB_ADMIN.OR_BLDG
(
B_ID NUMBER(8),
BLDG VARCHAR2(90 BYTE) NOT NULL
)
I do feel it is worthwhile to mention that I am using Oracle and I found a ticket that seems to describe what is happening to me but it was closed 18 months ago and no real details were provided on what was the problem/what was done to correct it.
I also found a comment in the "hasMany" section of the 1.2 CakePHP Book that reads:
If your hasMany association doesn't return any records, check if the column types of the primary key and the foreignKey are the same. If one is int and the other is char, you won't get any records from the association (and no warnings).
But, as you can see above, the key columns are NUMBERs on both ends (which is what CakePHP wants them to be for Oracle as well)