1

I am wondering whether I can use EntityFieldQuery to fetch all entities belonging to a specific content type. This entity type has a reference to another entity type. Is it possible to check against the refereed entities fields in the same query?

2 Answers 2

2

No.

An EntityFieldQuery allows you to run queries based on field and property conditions, but it has no way to query the fields or properties of a referenced entity.

Such a thing would involve some pretty full on logic, and it probably wouldn't even be possible to provide a programmatic interface to it that made sense.

0

What you would need to do is run a query against the referenced type first so you have all the node ids that apply, then use them in a second query with a field condition like:

->fieldCondition('YOUR_REFERENCE_FIELD', 'target_id', $nids, 'IN')

This may not be practical if your database is very large.

Your Answer

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

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