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?


bengt’s picture

Any suggestions?

bengt’s picture

The answer (for me, at least) is found here: http://drupal.org/node/1353926 (especially the comments).

jilladams’s picture

Title:Locating data within Field Collections with EntityFieldQuery» Locating data within Field Collections with EntityFieldQuery (or EFQ Views)
Version:7.x-1.0-beta3» 7.x-1.0-beta4
Category:support» feature
Priority:Normal» Major

Bumping 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.

jmuzz’s picture

Priority:Major» Normal
Issue summary:View changes