Note that there are some explanatory texts on larger screens.

plurals
  1. POYii CActiveDataProvider Many to Many
    primarykey
    data
    text
    <p>I do not understand how to implement a many to many relation in CActiveDataProvider.</p> <p>At first the situation, I have one Model "Company" with following relations:</p> <pre><code>return array( 'owner' =&gt; array(self::HAS_ONE, 'User', 'user_id'), 'admins' =&gt; array(self::MANY_MANY, 'User', '{{company_user}}(company_id,user_id)', 'condition' =&gt; 'is_admin = 1'), 'members' =&gt; array(self::MANY_MANY, 'User', '{{company_user}}(company_id,user_id)'), 'standard_members' =&gt; array(self::MANY_MANY, 'User', '{{company_user}}(company_id,user_id)', 'condition' =&gt; 'is_admin = 0'), ); </code></pre> <p>Now I want to get all admins of a company. Normally I did:</p> <pre><code>$company = Company::model()-&gt;find('company_id=1'); var_dump($company-&gt;with('admins')-&gt;findAll()); </code></pre> <p>So I have all administrators of a company.</p> <p>But I did not parse, how to do it with a CActiveDataProvider.</p> <pre><code>$dataProvider_admins = new CActiveDataProvider('Company', array( 'criteria' =&gt; array( 'with' =&gt; array( 'admins' =&gt; array('condition' =&gt; 'company_id='.$company-&gt;id) ), ), 'pagination' =&gt; array( 'pageSize' =&gt; 20, ), )); var_dump($dataProvider_admins-&gt;getData()); </code></pre> <p>But with this way I get a company record with all administrators, but not an array containing all administrators.</p> <p>Update: I could create an Model for the relation table <code>{{company_user}}</code> and use this, but I do not think its the right way, isn't it?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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