You probably want to add the foreigh_key to your hasMany and
belongsTo, especially if they don't follow the cake conventions.
In my models, I have ID columns like 'user_id', and the foreign_key is
typically the same name, so for instance in my Users to Groups
relationship I have something like:
// Users model ...
var $hasMany = array(
'UserGroup' => array(
'className' => 'UserGroup',
'foreignKey' => 'user_id',
'limit' => '5',
'dependent' => true
)
);
// Link to groups
var $hasAndBelongsToMany = array(
'Group' =>
array(
'className' => 'Group',
'joinTable' => 'user_groups',
'foreignKey' => 'user_id',
'associationForeignKey' => 'group_id',
'conditions' => '',
'order' => '',
'limit' => '',
'unique' => true,
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
// Groups model
var $hasMany = array(
'UserGroup' => array(
'className' => 'UserGroup',
'foreignKey' => 'group_id',
'limit' => '5',
'dependent' => true
)
);
// Link to users
var $hasAndBelongsToMany = array(
'User' =>
array(
'className' => 'User',
'joinTable' => 'user_groups',
'foreignKey' => 'group_id',
'associationForeignKey' => 'user_id',
'conditions' => '',
'order' => '',
'limit' => '',
'unique' => true,
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
On Nov 22, 9:45 am, "James.Diss" <[EMAIL PROTECTED]> wrote:
> The failing isn't really in understanding the relationships, just
> something odd is happening that I want to get a perspective on as a
> beginner.
>
> I have two models with backing database tables. The models are;
>
> // app/models/User.php
> class User extends AppModel {
> var $name = 'User';
> var $validate = array();
> var $hasMany = array('Post');
>
> }
>
> // app/models/Post.php
> class Post extends AppModel {
> var $name = 'Post';
> var $validate = array();
> var $belongsTo = array('User');
>
> }
>
> I also have two controllers that basically use the scaffold. The
> users controller does what it's supposed to do, but hitting the post
> controller doesn't show the user select box, which indicates to me
> that the relationship isn't being built. The foreign key in the posts
> table is 'user_id'.
>
> As I'm just getting started, I'm at a loss to debug what appears to be
> a very basic piece of code.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---