Just use regular find() with conditions:

$this->User->find(
        'first',
        array(
        'conditions' => array(
                'User.slug' => $slug
        ),
        'contain' => array(
                // ...
        )
);

On Sat, Apr 11, 2009 at 6:09 PM, Dave Maharaj :: WidePixels.com
<[email protected]> wrote:
>
> Can you use findBy with contain? I keep getting an error saying:
> Model "User" is not associated with model "User"
>
> I am trying to clean up my queries and I have:
> $user = $this->User->findBySlug($slug);
>
> which returns a lot of info from a lot of tables which is certainly not
> needed since all I need to get is in the same table as the slug, the User
> table so basically I want to findBy and contain to user table? Is that
> possible?
>
> MODEL:
> function slugToId($slug)
>        {
>                 $cntn = $this->User->contain('User');
>                 $q = $this->User->findBySlug($slug, $cntn);
>
>                 return $q;
>        }
>
> AGENT CONTROLLER:
> $test = $this->Agent->slugToId($slug);
>                  debug($test);
>
>
> TEST DEBUG:
> Warning (512): Model "User" is not associated with model "User"
> [CORE/cake/libs/model/behaviors/containable.php, line 340]
>
> app/controllers/agents_controller.php (line 131)
>
> Array
> (
>    [User] => Array
>        (
>            [id] => 3
>            [group_id] => 3
>            [username] => dave
>            [password] => -------------
>            [email] => -------------
>            [slug] => mickeymouse
>            [confirmed] => 1
>            [confirm_code] => 49cc5013-0380-4086-bd30-448c4adcd75b
>            [created] => 2009-03-26 22:03:31
>            [modified] => 2009-03-26 22:03:31
>        )
>
> )
>
>
> Dave
>
>
> >
>

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