Вопрос

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 ?

Это было полезно?

Решение

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?

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top