1

I read that entityCondition should take an array, and I've constructed an array according to examples I've seen on the web. But no dice. I get the error below. If I use a string, the error goes away.

Here's my code:

$query = new EntityFieldQuery();
$types = array('commerce_product', 'produce_share');
$query->entityCondition('entity_type', $types, 'IN');
$result = $query->execute();

And here's the error:

Warning: Illegal offset type in isset or empty in entity_get_info() (line 7690 of /**/includes/common.inc).
Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1573 of /**/includes/bootstrap.inc).
EntityFieldQueryException: Entity <em class="placeholder"></em> has no base table. in EntityFieldQuery->propertyQuery() (line 1209 of /**/includes/entity.inc).

2 Answers 2

1

Correct me if I'm wrong, but aren't commerce_product and product_share bundles not entity_type's (both of entity_type node)?

I think you may want:

// The types we're looking for.
$types = array('commerce_product', 'produce_share');

// Build the query.
$query = new EntityFieldQuery()

  // Looking for nodes.
  ->entityCondition('entity_type', 'node')

  // With the specific bundles.
  ->entityConditiion('bundle', $types, 'IN');

// Run the query.
$result = $query->execute();

https://www.drupal.org/node/1343708

1
  • Howdy. Thanks for the code! 'commerce_product' is an entity type, 'produce_share' is not. I had tried with a bunch of stuff before I posted. For instance, I tried it with ->entityCondition('entity_type', $types) where $types = array('comment', 'node'); These are undeniably entity types and I still get the error. Aug 18, 2014 at 21:46
1

I know this answer comes almost a year too late for you, but I dealt with the same problem and found out why the answer is you can't.

According to the API:

While the field storage engine might support field conditions on more than one entity type, there is no way to query across multiple entity base tables by default.

Which means you can't query both the comment and node entity types with one entity field query because they derive from two separate database tables.

Simple Solution: I performed two separate queries and concatenated the results together.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.