Cakephp key visible in index list but not value for linked table -
to make clearer (changed after first 2 comments below)...
councils controller index, problem numeric 'region_id' displayed on index view instead of linked 'region->name'.
function index() { $this->council->recursive = 0; $this->set('councils', $this->paginate()); } councils model:
var $belongsto = array( 'region' => array( 'classname' => 'region', 'foreignkey' => 'region_id', 'conditions' => '', 'fields' => '', 'order' => '' ) ); var $hasmany = array( 'person' => array( 'classname' => 'person', 'foreignkey' => 'council_id', 'dependent' => false, 'conditions' => '', 'fields' => '', 'order' => '', 'limit' => '', 'offset' => '', 'exclusive' => '', 'finderquery' => '', 'counterquery' => '' ) ); sql
-- -- table structure table `councils` -- create table if not exists `councils` ( `id` int(11) not null auto_increment, `name` varchar(40) default null, `email` varchar(40) not null, `website` varchar(40) not null, `websource` varchar(40) not null, `region_id` int(11) default null, primary key (`id`) ) engine=myisam default charset=latin1 auto_increment=17 ; -- -------------------------------------------------------- -- -- table structure table `regions` -- create table if not exists `regions` ( `id` int(11) not null auto_increment, `name` varchar(40) default null, primary key (`id`) ) engine=myisam default charset=latin1 auto_increment=20 ;
you're passing list of regions view correctly, need make sure relationship between 2 models set correctly. in council model, make sure have following:
var $belongsto = array( 'region' => array( 'classname' => 'region', 'foreignkey' => 'region_id' ) );
Comments
Post a Comment