0

I have a content type where there is a tag field that is a taxonomy term.I would like to make a query to get all the nodes that contain the $tag variable inserted by the user. I know how to do it using db_query but if I use EntityFieldQuery seems that I cannot apply a join.

How can I do it? Do I have to use db_query?

iknow
  • 8,358
  • 12
  • 41
  • 68
Cris
  • 12,124
  • 27
  • 92
  • 159

1 Answers1

1

An EntityFieldQuery doesn't allow for IS NOT NULL or similar conditions, so there's no way to query for all nodes that contain a value for a particular field. You can only query nodes that have a specific value for a particular field.

They're also self-contained, so there's no way to add an extra join unless you implement hook_query_alter() and physically add the join once the query has been converted from an EntityFieldQuery to a standard SelectQuery. That, or sub-class EntityFieldQuery and add the new logic yourself.

That said you'll need to form the query yourself. If you're just querying for nodes though, I'd advise using the taxonomy_index table rather than the field tables, as that will produce cleaner queries and make life easier further down the line.

Clive
  • 36,918
  • 8
  • 87
  • 113