Reputation: 2763
I have a two tables in database accommodations
and locations
. The accommodations
table structure is :
id name location_id
1 A 2
And the locations
table structure is similar to :
id name
2 PQ
The AccommodationModel.php
is:
class AccommodationModel extends AppModel{
var $name = 'Accommodation';
var $hasOne = array(
'Location' => array(
'className' => 'Location',
),
);
}
But when I tried to get the accommodation
name
and location
name
from AccommodationsController
$accommodations = $this->Accommodation->find('all',array('conditions' => $conditions,'order' => $order,'limit'=>$limit));
It only shows the Accommodation
array. Why so and how can I get the location name
?
Upvotes: 0
Views: 43
Reputation: 2073
What CakePHP-Version are you Using? Since 2.x its (without "Model" in Classname)
class Accommodation extends AppModel {
Anyways, here you go:
var $hasOne = array('Location');
..is all you need for simple hasOne - association, if you follow all Cake(Naming)Conventions.
Whats the result?
Upvotes: 1