Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to find data through foreign key in cakephp?
    text
    copied!<pre><code> Product Plan ProductPlan id |name id |name id | product_id | plan_id 1 aplha 1 a 1 1 2 2 bravo 2 b 3 charlie </code></pre> <p>I want to find Product name and Plan name against ProductPlan, if product id and plan id for product exist in ProductPlan then the name of plan and product will show, I tried a lot, the relation b/w tables are correct but i didn't get the exact data, query which i used that is</p> <pre><code> $p_plan = $this-&gt;ProductPlan-&gt;find('all',array( 'conditions'=&gt;array( 'ProductPlan.product_id'=&gt;'Product.product_id' ) ) ); $this-&gt;set('p_plan', $p_plan); </code></pre> <p>if some body help me , i'll very thaksful to him. Thanks in advance.</p> <p>Relation For Plan</p> <pre><code>class Plan extends AppModel{ public $primaryKey='plan_id'; public $hasMany = array( 'ProductPlan'=&gt;array( 'className' =&gt; 'ProductPlan', 'foreignKey' =&gt; 'plan_id' ) ); </code></pre> <p>Product</p> <pre><code>class Product extends AppModel{ public $primaryKey='product_id'; public $hasMany = array( 'ProductsUser'=&gt;array( 'className' =&gt; 'ProductsUser', 'foreignKey' =&gt; 'product_id' ), 'ProductsUserNode'=&gt;array( 'className' =&gt; 'ProductsUserNode', 'foreignKey' =&gt; 'product_id' ), 'ProductPlan'=&gt;array( 'className' =&gt; 'ProductPlan', 'foreignKey' =&gt; 'product_id' ) ); </code></pre> <p>for Product Plan </p> <pre><code>class ProductPlan extends AppModel{ var $primaryKey='product_plan_id'; public $belongsTo = array( 'Product' =&gt; array( 'className' =&gt; 'Product', 'foreignKey' =&gt; 'product_id' ), 'Plan' =&gt; array( 'className' =&gt; 'Plan', 'foreignKey' =&gt; 'plan_id' ) ); public $hasMany = array( 'ProductPlansUserNode'=&gt;array( 'className' =&gt; 'ProductPlansUserNode', 'foreignKey' =&gt; 'product_plan_id' ), ); </code></pre> <p>}</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