Monday, November 3, 2008

Re: hasMany bind on the fly

Hey Teknoid, you were helping me with this on IRC the other day,
thanks for this thread too! Your work is appreciated!!!

Luke

On Oct 31, 11:23 pm, teknoid <teknoid.cake...@gmail.com> wrote:
> no, cake can easily build the join that you need:http://teknoid.wordpress.com/2008/07/17/forcing-an-sql-join-in-cakephp/
>
> as matter of fact there is an example like like this one in the
> manual. and i must've posted this link on the list a bunch of times.
> so searching is always a good idea...
>
> On Oct 31, 6:06 pm, Ita <zip...@gmail.com> wrote:
>
> > Well since no shiny knight in white armor came to my rescue I wound up
> > creating my query.
> > I guess cake has its own limitations.
>
> > On Oct 30, 7:41 am, Ita <zip...@gmail.com> wrote:
>
> > > So it just can't handle the conditions?
> > > What should I do in this case? create my own query?
>
> > > On Oct 29, 7:29 pm, teknoid <teknoid.cake...@gmail.com> wrote:
>
> > > > cake does not create joins for hasMany (only hasOne and belongsTo)
>
> > > > On Oct 29, 12:27 pm, Ita <zip...@gmail.com> wrote:
>
> > > > > Hi,
> > > > > I have 2 models Item and Defect.
> > > > > both of them have description.
> > > > > an Item can have many Defects and my defects table has a an item_id
> > > > > field.
>
> > > > > Now I'm trying to create a search query that will search both the item
> > > > > description and the defect description.
> > > > > What I do is this:
>
> > > > > $this->Item->bindModel(
> > > > > array('hasMany' => array(
> > > > > 'Defect' => array(
> > > > > 'className' => 'Defect',
> > > > > 'foreignKey' => 'item_id',
> > > > > 'type' => 'INNER'
> > > > > )
> > > > > )
> > > > > )
> > > > > );
> > > > > then I run findAll.
>
> > > > > Now when I use findAll with no conditions everything works fine. cake
> > > > > seems to run 2 queries:
> > > > > SELECT `Item`.`id`,...... FROM `items` AS `Item` WHERE 1 = 1
> > > > > SELECT `Defect`.`id`,.......... FROM `defects` AS `Defect` WHERE
> > > > > `Defect`.`item_id` IN (1, 2, 16, 15, 14, 13, 12, 11, 10, 17, 18, 19,
> > > > > 20)
>
> > > > > My first question is why does cake doesn't create one query with INNER
> > > > > JOIN?
> > > > > The second problem is when I add conditions:
> > > > > $conditions[] = "`Item`.`name` LIKE '%" .$search_term ."%' OR
> > > > > `Defect`.`description` LIKE '%" . $search_term . "%'";
>
> > > > > It seems that cake in this case ignores the join all together and just
> > > > > does a regular select so I get an error:
> > > > > 1054: Unknown column 'Defect.description' in 'where clause'
>
> > > > > Does anyone know what I'm doing wrong?
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: