Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When not to use Containable Behavior in CakePhp 2.x

After a few times adding Containable Behavior to my various model classes, I have a good mind to simply chuck the line into AppModel instead and thus make every model Containable. Which then makes me wonder, is there any situation where it is not desirable or counterproductive for a particular model to have Containable Behavior?

like image 834
medcatt Avatar asked Dec 27 '22 07:12

medcatt


1 Answers

I would say too few to be worried about. I put containable in App Model:

class AppModel extends Model {
    public $recursive = -1;
    public $actsAs = array('Containable');

}

Containable overrides recursive anyway, so you don't really need to set recursive to -1, but I do just for clarity. Always using containable forces you into the best practice of always using only what you want/need. For small apps, it's not the end of the world to just use recursive and ignore containable, but it's still not best practice.

So, I guess the only argument for using recursive instead of containable would be that in small apps, you save yourself a tiny amount development time, and it won't really noticeably affect performance. I'd definitely go with using containable by default, and removing it where you deem it overkill, rather than the other way around.

like image 88
joshua.paling Avatar answered Dec 29 '22 10:12

joshua.paling