php - CakePHP, How to getting value from another table -
i have 2 table on model , table1 , table2 column on table1
id | content1
column on table2
id | table1_id | content2
i want display content in table1 on table2 , how join column?
thanks advance!
model\model1.php
<?php app::uses('appmodel', 'model'); class model1 extends appmodel { public $usetable = 'table1'; }
model\model2.php
<?php app::uses('appmodel', 'model'); class model2 extends appmodel { public $usetable = 'table2'; public $belongsto = array( 'model1' => array( 'classname' => 'model1', 'foreignkey' => 'table1_id' ) ); }
in controller:
$data = $this->model2->find('all');
the generated query
select `model2`.`id`, `model2`.`table1_id`, `model2`.`content2`, `model1`.`id`, `model1`.`content1` `db`.`table2` `model2` left join `cake244`.`table1` `model1` on (`model2`.`table1_id` = `model1`.`id`) 1 = 1
Comments
Post a Comment