Hi,
Your very close. You have everything setup correctly, but your trying to find
the project the wrong way.
$this->Project->findall(array('Task.id' => 1));
A project has many tasks, but a task belongs to just one project and just one
user.
So, if you have the task.id and you need the project. Then you should query by
the task model, and not the project.
$tasks = $this->Task->findById( 1 );
$tasks['Project'] will contain the records for that project.
$project = $this->Project->findById( 1 );
This will find project ID 1, and "all" of it's tasks.
$user = $this->User->findById( 1 );
$user is one record, but also contains an array of all the tasks for that user.
Understand?
----- Original Message ----
From: thewebguy <[EMAIL PROTECTED]>
To: CakePHP <[email protected]>
Sent: Friday, May 9, 2008 11:14:33 AM
Subject: Find Parent By Child
I'm having trouble with a findAll() query. I may not fully understand
how associations work, so I'm here for help.
So I've got 3 classes:
Class: Project
Fields: id, name
hasMany: Task
Class: Task
Fields: id, project_id, user_id, name
belongsTo: Project, User
Class: User
Fields: id, name
hasMany: Task
These queries all seem to work just fine [Assume the values I'm
searching are valid]:
$this->Task->findAll(array('User.id' => 1));
$this->Task->findAll(array('Project.id' => 1));
This query never returns any results [Assume the values I'm searching
are valid]:
$this->Project->findall(array('Task.id' => 1));
Is this not available with hasMany? How can I get around this?
Thanks!
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now.
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---