Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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 CreditAttribution: bengt commentedAny suggestions?
Comment #2
bengt CreditAttribution: bengt commentedThe answer (for me, at least) is found here: http://drupal.org/node/1353926 (especially the comments).
Comment #3
jilladams CreditAttribution: 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 CreditAttribution: jmuzz commentedComment #5
Alan D. CreditAttribution: 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