How to append to contain when it’s already declared?
-
I call a regular contain/find:
// A controller $this->Site->contain(array('User')); $site = $this->Site->find(); -
I want to automatically add something to contain. I was thinking of doing this in the Model by adding to the find function… something like this:
// Site.php Model function find($conditions = null, $fields = array(), $order = null, $recursive = null) { if(!isset($this->containVariable) || !in_array('Box', $this->containVariable)) { $this->containVariable[] = 'Box'; } parent::find($conditions, $fields, $order, $recursive); }
To make this work (automatically adding model Box to contain) I only need to change $this->containVariable by a function or variable that has an array of what’s already in contain. In this case this would return array('User'). How to append to contain when it’s already declared? Is there a variable that contains contain?
Unless someone can find another solution I’ve came to the conclusion that:
Unfortunately what I was trying to do seems impossible how containable is designed. I had to manually add my model to every
->contain()calls.