Better to use Cakephp Association.

On Fri, Dec 17, 2010 at 9:17 PM, Stephen <[email protected]>wrote:

> I find the best way to deal with User hasOne Profile to find a users "own"
> profile is to check the $this->Auth->user('id') against Profile.user_id;
> Other than that, you'd need to find the user via username etc and then get
> the user id.
>
> 2010/12/17 Flávio Ricardo <[email protected]>
>
>> I don't understand why you are doing this.
>>
>>
>> I think if you had a model called User wich hasOne UserProfile the
>> more correct to you find a User and retrieve your UserProfile. The
>> other solution is you  change the association to UserProfile belongsTo
>> User and set a field user_id.
>>
>> So you use $this->UserProfile->find('list', array('conditions' =>
>> array('user_id' => $id)));
>>
>> On Dec 16, 3:11 pm, psybear83 <[email protected]> wrote:
>> > Hey everybody
>> >
>> > I want to use find('list') that uses conditions of joined tables. But
>> > it seems find('list') doesn't support that?
>> >
>> > Example: I have a model User which hasOne UserProfile.
>> >
>> > $userProfile->find('all', array(
>> >             'conditions' => array(
>> >             )
>> >           ));
>> >
>> > ...works like a charm, but...
>> >
>> > $userProfile->find('list', array(
>> >             'conditions' => array(
>> >               'User.id' => $id
>> >             )
>> >           ));
>> >
>> > ...tells me:
>> >
>> > SQL Error: 1054: Unknown column 'User.id' in 'where clause' [CORE/cake/
>> > libs/model/datasources/dbo_source.php, line 684]
>> >
>> > Query: SELECT `UserProfile`.`id` FROM `user_profiles` AS `UserProfile`
>> > WHERE `User`.`id` = 1102
>> >
>> > Evidently it doesn't join the hasOne table by itself... Is there a way
>> > to force it to do it anyway?
>> >
>> > Thank you
>> > Josh
>>
>> 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 [email protected]
>> To unsubscribe from this group, send email to
>> [email protected]<cake-php%[email protected]>For
>>  more options, visit this group at
>> http://groups.google.com/group/cake-php?hl=en
>>
>
>
>
> --
> Kind Regards
>  Stephen @ NinjaCoderMonkey
>
>  www.ninjacodermonkey.co.uk
>
>
>
>  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 [email protected]
> To unsubscribe from this group, send email to
> [email protected]<cake-php%[email protected]>For
>  more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>



-- 
Thanks & regards.
------------------------------------
Yasir Arafat (Hasib)
Software Engineer
Epsilon Consulting and Development Services (ECDS)
Contact Information:
Cell : +8801816536901
Web: http://arafats.info

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