I'm running into some issues with getting Node Gallery Items to work with Entity Field Queries. I'm unable to filter results based on the parent gallery being referenced by the node gallery item. Here's some sample code that explains the issue.
First, I'll write an EFQ to produce an array of node ids belonging to all node galleries owned by a certain Organic Group. This part is fine.
$my_group_id = '150';
$query = new EntityFieldQuery();
$query->entityCondition('entity_type','node')
->entityCondition('bundle', 'node_gallery_gallery')
->fieldCondition('og_group_ref', 'target_id', $my_group_id);
$galleries = $query->execute();
$gallery_ids = array_keys($galleries['node']); // result: array(20, 50, 65);
Next, I should be able to then use my $gallery_ids to run another Entity Field Query to fetch a list of node ids for node gallery items that belong to the galleries represented in the $gallery_ids array that I just produced. This part doesn't work as expected.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type','node')
->entityCondition('bundle','node_gallery_item')
->fieldCondition('node_gallery_ref_1', 'target_id', $gallery_ids);
$items = $query->execute();
$items is an empty result set with 0 elements.
Ok, let's make sure that we're able to get any results at all for child nodes of my galleries. I'll change my EFQ to strip out the fieldCondition on 'node_gallery_ref_1'.
$query = new EntityFieldQuery();
$query->entityCondition('entity_type','node')
->entityCondition('bundle','node_gallery_item');
$items = $query->execute(); // Returns all node gallery items in database
I get the results I expected, but not the filtered results I was originally trying to get.
It seems that node_gallery_ref_1 is not being recognized as a valid field name for a fieldCondition for this type of entity. Is this a bug or am I missing something?
Comments
Comment #1
hyperlinked CreditAttribution: hyperlinked commentedComment #2
hyperlinked CreditAttribution: hyperlinked commentedComment #3
hyperlinked CreditAttribution: hyperlinked commentedComment #4
hyperlinked CreditAttribution: hyperlinked commentedComment #5
hyperlinked CreditAttribution: hyperlinked commentedComment #6
zengenuity CreditAttribution: zengenuity commentedThe entity reference data is not stored in the normal table location, which is probably why that doesn't work. Instead, it's used to create a Node Gallery Relationship entity. You will probably need to EFQ on that.
From the relationships you can get the nids.