Whats the best way to lookup data in Field Collections with EFQ?
I have a Field Collection with a couple of fields set to a host entity that contains a table of pricing information. When new prices are received from a third party service, I would like to query against the incoming option, locate it, and update its price.
Heres what I have been trying ($this->entity_id is a host entity ID, the other two $this values are assigned when looping the data):
$query = new EntityFieldQuery;
$query->entityCondition('entity_type', 'field_collection_item')
->entityCondition('bundle', 'field_trinkets')
->entityCondition('entity_id', $this->entity_id);
if (isset($this->trinket_option)) {
$query->fieldCondition('field_trinket_option', 'value', $this->trinket_option, '=');
}
if (isset($this->trinket_price)) {
$query->fieldCondition('field_trinket_price', 'value', $this->trinket_price, '=');
}
$trinket_record = $query->execute();
if ($trinket_record) {
$trinket_record = end(entity_load('field_collection_item', array_keys($trinket_record['field_collection_item'])));
return $trinket_record;
} else {
return FALSE;
}
Either way, no records are ever found when there should be matches most of the time. What am I missing?
Comments
Comment #1
bengt commentedAny suggestions?
Comment #2
bengt commentedThe answer (for me, at least) is found here: http://drupal.org/node/1353926 (especially the comments).
Comment #3
jilladams commentedBumping this, but in relation to EFQ Views. The Field Collection is only available as an entire entity, and the fields contained within can't be hooked/manipulated by the view.
Comment #4
jmuzz commentedComment #5
alan d. commentedUm, no issues when I just had a play, I Googled first to save some typing / investigation & hit this and other blank responses...
Tested on beta8