yep, you have to, that's how cakephp sets relationships between models
 in the User model you say something like

<?php
class User extends AppModel
{
        var $name = 'User';
        var $belongsTo = 'Group';

}
?>

and in the Group model
<?php
class Group extends AppModel
{
        var $name = 'Group';
        var $hasMany= 'User';

}
?>

 And that's it.
 IF you don't follow the cake conventions for ids, tables, or if you
need some different queries or conditions for a Model (for example,
you may want by default showing only users without administration
rights), you may need to be more verbose on these declarations, as
stated in the manual: http://manual.cakephp.org/chapter/models

    var $belongsTo = array('User' =>
                           array('className'  => 'User',
                                 'conditions' => '',
                                 'order'      => '',
                                 'foreignKey' => 'user_id'
                           )
                     );

    var $hasMany = array('Comment' =>
                         array('className'   => 'Comment',
                               'conditions'  => 'Comment.moderated = 1',
                               'order'       => 'Comment.created DESC',
                               'limit'       => '5',
                               'foreignKey'  => 'user_id',
                               'dependent'   => true,
                               'exclusive'   => false,
                               'finderSql'   => ''
                         )
                  );


 got it ? :)
 spark

On 8/29/06, eDevil <[EMAIL PROTECTED]> wrote:
>
> Sorry for the late reply. I had other stuff to do. So here's what I get
> with DEBUG = 2 and pr($user); die;
>
> Array
> (
>     [User] => Array
>         (
>             [id] => 1
>             [realname] => Saddam Azad
>             [username] => admin
>             [password] => 21232f297a57a5a743894a0e4a801fc3
>             [email] => [EMAIL PROTECTED]
>             [website] =>
>             [aim] =>
>             [yahooim] =>
>             [jabbergtalk] =>
>             [about] =>
>             [useavatar] => gravatar
>             [customavatar] =>
>             [created] => 2006-07-08 11:29:32
>             [modified] =>
>         )
>
> )
>
> 1 query took 91 ms Nr   Query   Error   Affected        Num. rows       Took 
> (ms)
> 1       SELECT `User`.`id`, `User`.`realname`, `User`.`username`,
> `User`.`password`, `User`.`email`, `User`.`website`, `User`.`aim`,
> `User`.`yahooim`, `User`.`jabbergtalk`, `User`.`about`,
> `User`.`useavatar`, `User`.`customavatar`, `User`.`created`,
> `User`.`modified` FROM `users` AS `User` WHERE (`User`.`username` =
> 'admin') LIMIT 1
>
> Looks like its not making any queries to the 'groups' table.
>
> btw, do I need to link up models by using 'hasMany' or 'belongsTo' etc ?
>
>
> >
>


-- 
[web] http://synapsisdi.com.br
[livesets] http://djspark.com.br

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to