1.  Follow the cake conventions - it makes life easier (
http://manual.cakephp.org/appendix/conventions ).

2.  In your example above, you want:
Person belongsTo Position, with foreign_id 'position'
Position hasMany Person, with foreign_id 'position'

3.  Make sure you are using scaffold for your controller to see these
association changes reflected in your views.


On Nov 29, 1:12 pm, powtac <[EMAIL PROTECTED]> wrote:
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to