Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP plugin models not associating when using Containable
    text
    copied!<p>I have a CakePHP plugin named <code>Foo</code> that has a component, no controller, and several joined models. It's structured like this:</p> <pre><code>/Plugin/Foo/Model/ -FooModel1.php -FooModel2.php -FooModel3.php -FooModel4.php </code></pre> <p>In order to connect with the standard (non-plugin) code, one of the plugin models is conditionally associated with a standard model called <code>Bar</code>. I don't believe this is relevant to the problem, but I want to be thorough.</p> <p>In <code>FooController</code> I make use of <code>Containable</code>, several layers deep:</p> <pre><code>$params = array( 'conditions' =&gt; array('Bar.id' =&gt; $bar_id), 'contain' =&gt; array( 'FooModel1' =&gt; array( 'FooModel2' =&gt; array( 'FooModel3' =&gt; array('Something', 'FooModel4') ), ), ), ); </code></pre> <p>This creates an error like:</p> <pre><code>Warning: Model "FooModel2" is not associated with model "FooModel3" [CORE\Cake\Model\Behavior\ContainableBehavior.php, line 339] </code></pre> <p>So in my plugin controller I need to contain plugin models. I've tried prefixing the models with Foo (e.g. <code>Foo.FooModel1</code>) but <code>Containable</code> thinks I'm trying to get a model named Foo. In the <code>$hasAndBelongsToMany</code> array in the plugin models I've tried both <code>'Model1' =&gt; array()</code> and <code>'Foo.Model1' =&gt; array()</code>, neither of which work. How do I correctly set up this association?</p> <p>Side note: when I move the models out of the plugin and into the standard <code>/Model/</code> directory everything works fine. The problem seems to come from incorrect associations rather than the logic of the code itself.</p> <p>Thanks a lot for the help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload