Jeremy,

thanks for the link, it was a bit buried in the depths of The Book, so
I didn't find it at first. Will check there now.. - Initial test
wasn't working, but I'll be getting there (I hope)! ;)

cheers!

nils


On 4 Jun., 15:28, Jeremy Burns <jeremybu...@me.com> wrote:
> Actually, looking at this a bit more, I'd like to pose a few questions.
>
> The general way of relating one table to another twice is that you give each 
> a different class name - in your case Sender and Recipient. You then do a 
> normal join, specifying the class name (User in your case) of the joining 
> table and then specify the foreign key - what are they in your case? I guess 
> the id column in the users table is User.id. What are the local keys in the 
> messages table? Are thy Message.sender_id and Message.recipient_id? If so, 
> the proper syntax would be:
>
>         var $hasOne = array(
>             'Sender' => array(
>                         'className' => 'User',
>                         'foreignKey' => 'sender_id'
>                 ),
>             'Recipient' => array(
>                         'className' => 'User',
>                         'foreignKey' => 'recipient_id'
>                 )
>         );
>
> See here for more 
> details:http://book.cakephp.org/view/1046/Multiple-relations-to-the-same-model
>
> Jeremy Burns
> jeremybu...@me.com
> (Skype) +44 208 123 3822 (jeremy_burns)
> (m) +44 7973 481949
> (h) +44 208 530 7573
>
> On 4 Jun 2010, at 14:18, Jeremy Burns wrote:
>
> > Try:
> >    var $hasOne = array(
> >        'Sender' => array(
> >                    'className' => 'User',
> >                    'foreignKey' => 'sender',
> >                    'conditions' => 'User.id = Message.sender',
> >                    'fields' => '',
> >                    'order' => ''
> >            ),
> >        'Recipient' => array(
> >                    'className' => 'User',
> >                    'foreignKey' => 'recipient',
> >                    'conditions' => 'User.id = Message.recipient',
> >                    'fields' => '',
> >                    'order' => ''
> >            )
> >    );
>
> > Jeremy Burns
> > jeremybu...@me.com
>
> > On 4 Jun 2010, at 14:17, nils wrote:
>
> >> Hi all,
>
> >> I've got a "messages" model with two fields called "sender" and
> >> "recipient" which I'd like to link to the users table.
>
> >> I tried:
> >> ---------->
> >>        var $hasOne = array(
> >>            'User' => array(
> >>                        'className' => 'User',
> >>                        'foreignKey' => 'sender',
> >>                        'conditions' => 'User.id = Message.sender',
> >>                        'fields' => '',
> >>                        'order' => ''
> >>                ),
> >>            'User' => array(
> >>                        'className' => 'User',
> >>                        'foreignKey' => 'recipient',
> >>                        'conditions' => 'User.id = Message.recipient',
> >>                        'fields' => '',
> >>                        'order' => ''
> >>                )
> >>        );
> >> <----------
>
> >> ..which doesn't lead to anything, although it *looks* obvious! :)
>
> >> Any ideas?
>
> >> TIA,
>
> >> nils
>
> >> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others 
> >> with their CakePHP related questions.
>
> >> You received this message because you are subscribed to the Google Groups 
> >> "CakePHP" group.
> >> To post to this group, send email to cake-php@googlegroups.com
> >> To unsubscribe from this group, send email to
> >> cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> >> athttp://groups.google.com/group/cake-php?hl=en
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd help others 
> > with their CakePHP related questions.
>
> > You received this message because you are subscribed to the Google Groups 
> > "CakePHP" group.
> > To post to this group, send email to cake-php@googlegroups.com
> > To unsubscribe from this group, send email to
> > cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> > athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to