CakePHP - hasMany not fetching?
Posted
by Paolo Bergantino
on Stack Overflow
See other posts from Stack Overflow
or by Paolo Bergantino
Published on 2010-06-10T22:02:20Z
Indexed on
2010/06/10
22:43 UTC
Read the original article
Hit count: 340
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?
© Stack Overflow or respective owner