Data model:
One person can have only one position.
One position can be used by many persons.
How do I get this relation into my view? So, I can select the
"position.name" in my person view as HTML drop down?
SQL:
CREATE TABLE `person` (
`personId` int(10) unsigned NOT NULL auto_increment,
`name` varchar(255) default NULL,
`email` varchar(255) default NULL,
`position` int(10) unsigned default NULL,
PRIMARY KEY (`personId`)
)
CREATE TABLE `position` (
`positionId` int(10) unsigned NOT NULL auto_increment,
`name` varchar(255) default NULL,
PRIMARY KEY (`positionId`)
)
Model:
class Person extends AppModel {
var $name = 'Person';
var $useTable = 'person';
var $primaryKey = 'personId';
var $hasOne = array('position' =>
array('className' => 'Position',
'conditions' => '',
'order' => '',
'dependent' => true,
'foreignKey' => 'positionId'
)
);
}
class Position extends AppModel {
var $name = 'Position';
var $useTable = 'position';
var $primaryKey = 'positionId';
var $belongsTo = array('People' =>
array('className' => 'Person',
'conditions' => '',
'order' => '',
'foreignKey' => 'personId'
)
);
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---