I am setting up a Real Estate system using CakePhp 2.x. My problem is I cannot relate my Owner Table(hasMany) to my Deed Table(hasOne and hasOne). I have been following this Models with two hasOne relations to same table The first table is Owner has the following columns:
id | lastName | firstName | middleName | etc...
The second table is Deed has the following columns:
id | owner_buyer | owner_seller | etc...
In the table Deed the owner_buyer and owner_seller are both Owners, and i can't change both the owner_buyer and owner_seller columns to owner_id. I have statically entered the owner ids for each deed but I am unable to retrieve the owner information.
Here is some additional information:
Deed Model:
App::uses('AppModel', 'Model');
class Deed extends AppModel {
public $hasOne = array(
'OwnerA' => array(
'className' => 'Owner',
'foreignKey' => 'owner_buyer'
),
'OwnerB' => array(
'className' => 'Owner',
'foreignKey' => 'owner_seller'
)
);
}
Owner Model:
App::uses('AppModel', 'Model');
class Owner extends AppModel {
public $hasMany = array(
'Deed' => array(
'className' => 'Deed',
'finderQuery' => 'SELECT * FROM deeds AS Deed WHERE Deed.owner_buyer_id = {$__cakeID__$} OR Deed.owner_seller_id = {$__cakeID__$};'
)
);
}
deedList.ctp
...
<td><?php echo $deed['Owner']['owner_buyer']; ?></td>
<td><?php echo $deed['Owner']['owner_seller']; ?></td>
...
buyer and seller both give me the following Notice:
Notice (8): Undefined index: Owner
Any help would be greatly appreciated!
Looking at the notice I think you have problem with the variable $deed. Could you copy and paste all information about notice?
Moreover, try to add debug($deed) in your ctp file and check if actual structure fits with your expectation.
Salvo