2

Problem

I'm trying to locate a node using EntityFieldQuery. Using fieldCondition removes all of my search results. What am I doing wrong?

So Far

I've built my function using How to use EntityFieldQuery. It's running in a custom form submit.

function mymodule_form() {

   $query = new EntityFieldQuery();

   $query
     ->entityCondition('entity_type', 'node')
     ->entityCondition('bundle', 'contact_details')
     ->fieldCondition('field_user_reference_manual', 'value', '154');

   $result = $query->execute();

}

If I remove the fieldCondition query line it returns both contact_details nodes that I've created. One has field_user_reference_manual = 154 the other 140

The important values in my MySQL table are:

Field: field_data_field_user_reference_manual

Column: field_user_reference_manual_value

6
  • From the description you're using a text field to hold a reference to a user - are you absolutely sure the field type isn't user_reference or entity_reference?
    – Clive
    Commented Sep 18, 2013 at 16:29
  • Yep it's an integer field. I put manual in the field so I wouldn't get confused. I also have a user_reference field but that's called field_user_permission. (I admit perhaps not the best naming scheme). I've tried the query with other fields on contact_details including a text one but none of them work. Commented Sep 18, 2013 at 16:34
  • Hmm, if the field name and column name are correct then your code is also correct - to rule out a permissions issue, try adding $query->addMetaData('account', user_load(1)) before it executes and see if that makes a difference
    – Clive
    Commented Sep 18, 2013 at 16:43
  • Thank you so much, you've now saved my terrible day twice. I'm a little confused though, why would a query run in a module have permissions issues? Does it inherit the permissions of the user it's run by? (By chance I've been testing this on a non-administrator account) Commented Sep 18, 2013 at 16:47
  • Certainly does, it's a very handy feature...unless you don't know about it ;) I've just found a duplicate of this actually so I'll close this to point at the other one - it's got a couple of good answers, no point in reproducing them here. BTW if you're just getting into Drupal development I'm sorry to say you'll probably have a few more of these days, the learning curve is pretty steep. The payoff is worth it though!
    – Clive
    Commented Sep 18, 2013 at 16:52

0

Browse other questions tagged or ask your own question.