I'm currently developing a project using CakePHP where users can create projects. Each project has only one administrator user, but other users should be able to "view" the project. How should I create this "view" option to users? I've already done the following model associations: [Users Model] hasMany [Projects] (by the time each user can have many projects).
I'm kinda perplexed now and I don't know exactly what additional model association i should create :/ I think a belongsTo or a HasAndBelongsToMany but i'm not sure :/ Can you help me out here?
thank you in advance!
You need to have 3 database tables
CakePHP Models
User
public $useTable = 'users';
public $hasMany = array(
'ProjectAsAdmin' => array(
'className' => 'Project')
);
public $hasAndBelongsToMany = array(
'ProjectAsMember' => array(
'className' => 'Project')
);
Project
public $useTable = 'projects';
public $hasAndBelongsToMany = array(
'Member' => array(
'className' => 'User')
);
public $belongsTo = array(
'Administrator' => array(
'className' => 'User',
'foreignKey' => 'administrator'
)
);