Maybe do you have to set $primaryKey on your controller.

Like:
class Posts extends AppModel {
   ...
   var $primaryKey = 'post_id';
   ...
}

On Jan 22, 2008 10:13 AM, Eemerge <[EMAIL PROTECTED]> wrote:

>
> Hello,
>
> I have 3 tables:
>
> 1. posts
> 2. categories
> 3. post_2_cat
>
> I am trying to use hasAndBelongsToMany to fetch a post and its
> associated categories (from post_2_cat)
>
> The only problem i encountered so far is with table fields names.
> Initially i had post_id and category_id in the posts and categories
> tables. This way, i dont get anything returned with
> hasAndBelongsToMany.
> If i modify the fields names to 'id' , i get the expected results.
>
> var $hasAndBelongsToMany=array('Category'=>
>
>
>  array('className'    => 'Category',
>                                     'joinTable'    => 'post_2_cat',
>                                     'foreignKey'   => 'post_id',
>                                     'associationForeignKey'=>
> 'cat_id',
>                                     'conditions'   => '',
>                                     'order'        => '',
>                                     'limit'        => '',
>                                     'unique'       => true,
>                                     'finderQuery'  => '',
>                                     'deleteQuery'  => '',
>                               )
>
> Above is the code that does this (resides in models/post.php).
>
> My question is, how can i use hasAndBelongToMany but not have to use
> "id" in my tables (for example i want to use: post_id instead of id ,
> in the posts table).
>
> Thanks in advance. Also, any other advices are welcome as im quite new
> to cakephp (which rocks btw :) )
> >
>


-- 
Renan Gonçalves - Web Developer
Cell Phone: +55 (11) 8633-6018
MSN: [EMAIL PROTECTED]
Web Site: renangoncalves.com
São Paulo - SP/Brazil

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