Hi Devs
I would like some more eyes on my query. It is not producing the SQL I expect.
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.
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.
Anyone got any more insight ?
Thanks very much
Peter
<code>
$query = new EntityFieldQuery;
$query
->entityCondition('entity_type', 'user')
->fieldCondition('group_audience', 'gid', $gid)
->fieldCondition('group_audience', 'state', (array) $states, 'IN');
</code>
<sql>
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
FROM field_data_group_audience field_data_group_audience0
INNER JOIN field_data_group_audience field_data_group_audience1 ON field_data_group_audience1.entity_type = field_data_group_audience0.entity_type
AND field_data_group_audience1.entity_id = field_data_group_audience0.entity_id
WHERE
( field_data_group_audience0.group_audience_gid = '2' ) AND (field_data_group_audience1.group_audience_state IN ('1'))
AND ( field_data_group_audience0.deleted = '0' ) AND ( field_data_group_audience0.entity_type = 'user' ) LIMIT 0 , 30
</sql>
The output (slightly modified to add state), gives me this:
| entity_type
| state
| entity_id
| revision_id
| bundle
|
| user |
1 |
1 |
1 |
user |
| user |
3 |
2 |
2 |
user |
Not sure if the formatting will hold, but, due to the joins, I am getting both states 1 and 3.