Jump to content

$belongsto relations


Iluvatar+

Recommended Posts

This is a long shot like seen as no one seems to respond to any cakephp related questions/problems.

But anyway here it goes…

I need to create a simple relationship between tables (User.id => Pages.user_id). I have created relationships before in cake but only in order to find and display data in the controller or the view.  I need this specific relationship to be set in the model ‘User’, the reason why is that I want the Auth (current user) session to contain its foreign relations in order to use that related data to set permissions within the User controller.

This is my model ATM

class User extends AppModel {
var $name = 'User';
var $belongsTo = array(Page => array('className'     => Page,
            											 					          		  'foreignKey'    => user_id,
        )
    );

 

From how I have read the syntax is fine, it’s just seems as though cake automatically assumes that the foreign key is within the user model rather than the pages  model.

 

Link to post
Share on other sites

Can you please show your table descriptions. 

 

E.g., "Describe table users", "Describe table pages"

 

FYI, you can use the bake console utility to create your basic models, controllers, views as long as your DB uses the cake conventions.

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.