Hi AD

cool..that works..great...

however, I am not sure why associationForeignKey does not work. I
checked the model class and it seems associationForeignKey is never
loaded for belongsTo...is that an error or this query I am trying to
specify is exceptional..

n'ways..thank you for suggestion..

Regards,
Ritesh

On Apr 12, 7:44 am, "AD7six" <[EMAIL PROTECTED]> wrote:
> On 12 abr, 13:35, "bingo" <[EMAIL PROTECTED]> wrote:
>
>
>
>
>
> > Hi,
>
> > I am trying to specify this self join + groub by query (see below my
> > query example). However, I am not joining the table on id but on
> > another field.
>
> > select ArticlesKeywordsUser.article_id, SelfJoinOnArticle.article_id,
> > count(*) as nos from articles_keywords_users as ArticlesKeywordsUser
> > leftJoin articles_keywords_users as SelfJoinOnArticle where
> > ArticlesKeywordsUser.article_id = SelfJoinOnArticle.article_id group
> > by ArticlesKeywordsUser.keyword_id, SelfJoinOnArticle.keyword_id
>
> > To do this, I defined my model as follows
>
> > class ArticlesKeywordsUser extends AppModel{
> >   var $name = 'ArticlesKeywordsUser';
>
> >   var $belongsTo = array(
> >                      'SelfJoinOnKeyword' => array(
> >                                'className' => 'ArticlesKeywordsUser',
> >                                'foreignKey' => 'article_id',
> >                                'associationForeignKey' => 'article_id'
> >                       )
>
> >   );
>
> > }
>
> > and in my controller I am specifying the query like this
>
> > $this->{$this->modelClass}->expects('SelfJoinOnArticle');
> > $this->{$this->modelClass}->findAll('1 = 1 group by
> > ArticlesKeywordsUser.keyword_id, SelfJoinOnArticle.keyword_id',
> > 'ArticlesKeywordsUser.article_id, SelfJoinOnArticle.article_id,
> > count(*) as nos')
>
> > However the final query produced by CakePHP is not what I intented.
> > Everything works as I thought, but instead of join on article_id it
> > does ArticlesKeywordsUser.article_id = SelfJoinOnArticle.id --- which
> > I dont want
>
> I wouldn't expect associationForeignKey to be even looked at for a
> belongsTo.
>
> just cheat,
>
> do $this->Article->primaryKey = 'article_id'; before you call the
> find.
>
> If that doesn't work or give an idea how to get it to work, an
> indication of your table structure would be useful.
>
> hth,
>
> AD- Hide quoted text -
>
> - Show quoted text -


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