I'm not sure you are interpreting it correctly, the way the associations should work.
Anyway, here is how I ended up coding it, as the result of Grant's reply, and it does works. In my model, post.php: var $belongsTo = array('User' => array('className' => 'User', 'conditions' => '', 'order' => '') ); In my model, user.php var $hasMany = array('Post' => array('className' => 'Post', 'conditions' => '', 'order' => 'Post.Id DESC', 'limit' => '', 'foreignKey' => 'user_id', 'dependent' => false, 'exclusive' => false, 'finderQuery' => '' ) ); --------------------------------------------- The way my tables work : In my Post table, I have a "user_id" field. -- Each post can only have at the most one single user associated with it. -- But I can't use hasOne, because I'm not linking the user table with the Post's primary key. I'm simply taking some field in my posts table, user_id, and linking another table to it. My User table: -- Each user can possibly have many posts. -- In this case, there is a direct link between "users" table and "posts" table, and this is the user_id field. So above I can specify a foreign_key, and this is user_id. Hope this clears some things up and didn't confuse you. On Sep 23, 4:49 pm, uoL <[EMAIL PROTECTED]> wrote: > Hello, > > I have a similar problem, I have a table > > Ads > > and a table > > Models > > The logic says an Ad has one Model and a Model belongs lo many Ads > > but when I put that logic in the model Ad I get a Unknown column > 'Model.model_id'. but as beetlecube said is the table Ad which have > the foreign key > In this case HasMany asociation is not the case i think. > do cake need to have tables linked that way or something ? > > Thanks! > > On 6 sep, 00:02, beetlecube <[EMAIL PROTECTED]> wrote: > > > Okay, thanks Grant. > > > On Sep 4, 10:36 pm, Grant Cox <[EMAIL PROTECTED]> wrote: > > > > You want Post belongsTo User, User hasMany Post. > > > > On Sep 5, 3:25 pm, beetlecube <[EMAIL PROTECTED]> wrote: > > > > > Hi, hope someone can clear this simple thing up. > > > > > I have a Post model (posts table) > > > > ------------------------- > > > > Pri Key: int ID > > > > varchar[100] comment > > > > int User_id ( the user who posted it of course ) > > > > > and a User model (users table) > > > > --------------------------------- > > > > Pri Key int ID > > > > > varchar username .. other fields, too... > > > > > On my Posts view thtml page, I need for my findAll (run from posts > > > > controller of course) to get all of my Posts plus the User table > > > > record that belongs to that post. > > > > > But if I have a $hasOne in the Post model, the query attempts to join > > > > the Post.ID field with User.user_id which doesn't work of course. > > > > > But User table doesn't have any fields relating to posts at all. I > > > > simply have a user_id in the posts table so that I know who posted > > > > what. > > > > > Do I need to just use the Execute api call from the Model class to > > > > manually run this query? > > > > > It looks like cakePHP is needing for the Post.ID field specifically to > > > > link up to a foreign id in User. > > > > > Steve --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---