I have 2 tables, Forumcategories and Forums…they both belong to multiple projects. I am loading a project and trying to contain all the forum categories. I have projects_forumcategories in my database and a has many. Do I also need a Belongstomany association and how would I write a query somewhere along the lines of “$forumcategories= $project->Forumcategories” or "$forumcategories = $this->Forumcategories->where(“contains->project_id”)?
So I have 5 Forumcategories that belong to multiple projects, and ditto setup with forums, I simply want to get only the forumcategories and forums that are decended from ONE project. I have done this with my Tasks model, but one task can only have one project. how would I do this to check if it has multiple projects. I don’t even know how to really phrase my question well, help would be appreciated! This is what I have so far:
public function view($id = null)
{
$this->loadModel(‘Tasks’);
$this->loadModel(‘Forumcategories’);
$this->loadModel(‘Forums’);
$paginate = [‘Tasks’ => [‘conditions’ => [‘project_id’ => $id]]];
$project = $this->Projects->get($id, [
'contain' => ['Users', 'Tasks' => ['Users'], 'Forumcategories' => ['Forums'], 'Events', 'Files']
]);
$tasks = $this->Tasks->find('all')->where(['project_id' => $id])->contain(['Users']);
$forumcategories = $this->Forumcategories->find('all');
$files = $this->paginate($project->Files, ['scope' => 'file']);
$this->set('project', $project);
$this->set('forumcategories', $forumcategories);
$this->set('tasks', $this->Paginate($tasks));
}