You want to search Pieces and list the lessons related to those
pieces?

$this->Lesson->Piece->recursive = 1;
$this->Lesson->Piece->findAll(array("Piece.name LIKE '%asd%'"));

or to just get all lessons and thier related pieces

$this->Lesson->recursive = 1;
$this->Lesson->findAll();


On Oct 25, 11:47 am, EVan <[EMAIL PROTECTED]> wrote:
> 4 hours later, still can't figure this out.....
>
> I've found that...
>
> $this->Lesson->Piece->findAll(array('Piece.id'=>'1'));
>
> will return some Lesson info...
>
> but I was under the impression
>
> $this->Lesson->Piece->findAll() was incorporated in
>
> $this->Lesson->findAll()
>
> ?
>
> On Oct 25, 12:21 pm, EVan <[EMAIL PROTECTED]> wrote:
>
> > I'm on day two of trying to figure this out, we'll see if this helps.
>
> > I've got three Models.  Lessons belongsTo Parts and Lessons HABTM
> > Pieces (and vice-versa)
>
> > Here's the model definition for Lessons, pretty straightforward.
>
> > class Lesson extends AppModel {
> >         var $name = 'Lesson';
> >         var $belongsTo = array(
> >                 'Part' => array(
> >                         'className' => 'Part',
> >                         'foreignKey' => 'part_id'
> >                 )
> >         );
>
> >         var $hasAndBelongsToMany = array(
> >                 'Piece' => array(
> >                         'className' => 'Piece',
> >                         'joinTable' => 'lessons_pieces',
> >                         'foreignKey' => 'lesson_id',
> >                         'associationForeignKey'=> 'piece_id',
> >                         'unique' => true
> >                 )
> >         );
>
> > }
>
> > The problem comes when trying to use findAll to locate a lesson
> > associated with a particular piece.  This is the findAll command I'm
> > using with the conditions array....
>
> > $resultArray = $this->Lesson->findAll(array('Piece.id' => '1',
> > 'Lesson.part_id' => '2'));
>
> > Looking at the SELECT query generated by Cake, I see that, unlike the
> > parts table, the pieces table is essntially ignored by findAll even
> > though there's a HABTM association, thus the WHERE part of the query,
> > where I ask for Piece.id, generates an error.
>
> > Query: SELECT `Lesson`.`id`, `Lesson`.`created`, `Lesson`.`modified`,
> > `Lesson`.`title`, `Lesson`.`issue`, `Lesson`.`part_id`, `Part`.`id`,
> > `Part`.`part` FROM `lessons` AS `Lesson` LEFT JOIN `parts` AS `Part`
> > ON (`Lesson`.`part_id` = `Part`.`id`) WHERE `Piece`.`id` = 1 AND
> > `Lesson`.`part_id` = 2
>
> > I'm confused as to how I might search for HABTM model associations via
> > a simple method such as findAll...  I feel this might be related to
> > the following --->  https://trac.cakephp.org/ticket/1209


--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to