Hi Devs<div><br></div><div>I would like some more eyes on my query. It is not producing the SQL I expect. </div><div><br></div><div>Working with OG for D7, I am looking to select all the group users with a specific state. I would have expected this code to do what I wanted, but, it does not. </div>
<div><br></div><div>I have attached the code and sql below. The SQL is the result of running the query on gid = 2 and states = 1. When run, I am getting results for both states 1 and 3. </div><div><br></div><div>Anyone got any more insight ? </div>
<div><br></div><div>Thanks very much </div><div><br></div><div>Peter</div><div><br></div><div><br></div><div><br></div><div><code></div><div><div> $query = new EntityFieldQuery;</div><div> $query</div><div> ->entityCondition('entity_type', 'user')</div>
<div> ->fieldCondition('group_audience', 'gid', $gid)</div><div> ->fieldCondition('group_audience', 'state', (array) $states, 'IN');</div></div><div></code></div><div>
<br></div><div><br></div><div><br></div><div><br></div><div><sql></div><div><div>SELECT DISTINCT field_data_group_audience0.entity_type AS entity_type, field_data_group_audience0.entity_id AS entity_id, field_data_group_audience0.revision_id AS revision_id, field_data_group_audience0.bundle AS bundle</div>
<div>FROM field_data_group_audience field_data_group_audience0</div><div>INNER JOIN field_data_group_audience field_data_group_audience1 ON field_data_group_audience1.entity_type = field_data_group_audience0.entity_type</div>
<div>AND field_data_group_audience1.entity_id = field_data_group_audience0.entity_id</div><div>WHERE </div><div>( field_data_group_audience0.group_audience_gid = '2' ) AND (field_data_group_audience1.group_audience_state IN ('1'))</div>
<div>AND ( field_data_group_audience0.deleted = '0' ) AND ( field_data_group_audience0.entity_type = 'user' ) LIMIT 0 , 30 </div></div><div></sql></div><div><br></div><div><br></div><div>The output (slightly modified to add state), gives me this: </div>
<div><br></div><div><p></p>
<table id="table_results" class="data">
<thead><tr>
<th class="condition">entity_type
</th><th>state
</th><th>entity_id
</th><th>revision_id
</th><th>bundle
</th></tr>
</thead>
<tbody>
<tr class="odd">
<td class=" condition">user</td>
<td class="">1</td>
<td class=" nowrap" align="right">1</td>
<td class=" nowrap" align="right">1</td>
<td class="">user</td>
</tr>
<tr class="even">
<td class=" condition">user</td>
<td class=" condition">3</td>
<td class=" nowrap" align="right">2</td>
<td class=" nowrap" align="right">2</td>
<td class="">user</td></tr></tbody></table></div><div><br></div><div><br></div><div>Not sure if the formatting will hold, but, due to the joins, I am getting both states 1 and 3. </div><div><br></div><div><br></div><div>
<br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div>