Still doesn't work:

    debug(
      $this->find(
        'count', array(
          'joins' => array(
            array(
              'alias' => 'Post',
              'table' => 'posts',
              'type' => 'left',
              'conditions' => array(
                'MetaTag.id' => $this->id
              )
            )
          )
        )
      )
    );

results in

Warning (512): SQL Error: 1066: Not unique table/alias: 'Post'
[CORE/cake/libs/model/datasources/dbo_source.php, line 684]
Query: SELECT COUNT(*) AS `count` FROM `meta_tags` AS `MetaTag` left
JOIN posts AS `Post` ON (`MetaTag`.`id` = '1601') LEFT JOIN `posts` AS
`Post` ON (`MetaTag`.`post_id` = `Post`.`id`) WHERE 1 = 1

I'm using CakePHP 1.3.6... Anyone of you guys successfully used the
joins feature? Seems to be rather complicated to me... ;-)

On Mon, Dec 13, 2010 at 6:01 AM, eugenioc...@hotmail.com
<eugenioc...@gmail.com> wrote:
> try using
>          'MetaTag.id' => $this->id
>
> instead of
>>         'MetaTag.id' => $this->id()
>
>
> the correct find sentence will be;
>
>  $this->find(
>         'count',
>         array(
>                 'joins' => array(
>                         array(
>                                 'alias' => 'Post',
>                                 'table' => 'posts',
>                                 'type' => 'left'
>                                 'conditions' => array(
>                                      'MetaTag.id' => $this->id
>                                 )
>                          )
>                   )
>            )
>  );
>
>
>
>
>
>
> On 12 dic, 21:37, McBuck DGAF <mcbuckd...@gmail.com> wrote:
>> How about:
>>
>> $this->find(
>>         'count',
>>         array(
>>                 'joins' => array(
>>                         array(
>>                                 'alias' => 'Post',
>>                                 'table' => 'posts',
>>                                 'type' => 'left'
>>                                 'conditions' => array(
>>                                      'MetaTag.id' => $this->id()
>>                                 )
>>                          )
>>                   )
>>            )
>> );
>>
>> On Dec 11, 6:57 pm, Joshua Muheim <psybea...@gmail.com> wrote:
>>
>> > Thanks, but while hoping that DRY and convention over configuration
>> > would apply here too, adding these informations still results in an
>> > invalid SQL statement:
>>
>> > SELECT COUNT(*) AS `count` FROM `meta_tags` AS `MetaTag` Post posts
>> > left LEFT JOIN `posts` AS `Post` ON (`MetaTag`.`post_id` =
>> > `Post`.`id`)  WHERE `MetaTag`.`id` = 1601 AND `Post`.`user_id` = 1103
>>
>> > On Sun, Dec 12, 2010 at 12:34 AM, cricket <zijn.digi...@gmail.com> wrote:
>> > > On Sat, Dec 11, 2010 at 2:27 PM, psybear83 <psybea...@gmail.com> wrote:
>> > >> Hey everybody
>>
>> > >> class MetaTag extends AppModel {
>> > >>        var $name = 'MetaTag';
>> > >>        var $displayField = 'name';
>>
>> > >>        function allowsAdd(&$user, $options) {
>> > >>                $this->find('count', array('joins' => array('Post'),
>> > >> 'conditions' => array('MetaTag.id' => $this->id())));
>> > >>        }
>> > >> }
>>
>> > >> This simple JOIN gives me a wrong SQL command:
>>
>> > >> SELECT COUNT(*) AS `count` FROM `meta_tags` AS `MetaTag` Post LEFT
>> > >> JOIN `posts` AS `Post` ON (`MetaTag`.`post_id` = `Post`.`id`)  WHERE
>> > >> `MetaTag`.`id` = 1601
>>
>> > >> ...while the correct one would look like this:
>>
>> > >> SELECT COUNT(*) AS `count` FROM `meta_tags` AS `MetaTag` LEFT JOIN
>> > >> `posts` AS `Post` ON (`MetaTag`.`post_id` = `Post`.`id`)  WHERE
>> > >> `MetaTag`.`id` = 1601
>>
>> > >> Where does this "Post" word come from?? Do I do anything wrong?
>>
>> > > There are no keys to the joins array. It should be an array of arrays.
>>
>> > > $this->find(
>> > >        'count',
>> > >        array(
>> > >                'joins' => array(
>> > >                        array(
>> > >                                'alias' => 'Post',
>> > >                                'table' => 'posts',
>> > >                                'type' => 'left'
>> > >                        )
>> > >                ),
>> > >                'conditions' => array(
>> > >                        'MetaTag.id' => $this->id()
>> > >                )
>> > >        )
>> > > );
>>
>> > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp 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 cake-php@googlegroups.com
>> > > To unsubscribe from this group, send email to
>> > > cake-php+unsubscr...@googlegroups.com For more options, visit this group 
>> > > athttp://groups.google.com/group/cake-php?hl=en
>
> 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 cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en
>

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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to