in some controller action this- Ressource- Behaviors- attach Containab

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?
//in some controller action
//
$this->Ressource->Behaviors->attach('Containable');
$this->Ressource->bindModel(array('hasMany' => array( 'Reservation' => array(
'conditions' => array(
'status' => array('booked', 'confirmed')
)
) ) ) );
$this->Ressource->find('all', array(
'contain'=> array(
'Reservation' => array('User')
),
'conditions'=>array(
'active' => true
)
));
/*
Producing queries:
SELECT 'Ressource' ... WHERE `active` = '1'
SELECT 'Reservation' ... WHERE 'ressource_id' IN (1,2,3) AND 'status' IN ('booked', 'confirmed')
AND NOW!
SELECT User ... WHERE id=...
SELECT User ... WHERE id=...
SELECT User ... WHERE id=...
and so on. Why cake is't using Reservation LEFT JOIN User for it?
*/
?>
<?
//Reservation Model
...
var $belongsTo = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'fe_user_id'
)
);
?>