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 <[email protected]> wrote:
> On Sat, Dec 11, 2010 at 2:27 PM, psybear83 <[email protected]> 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 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 [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
>

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