1

I have created a custom entity, called 'point'.

I'm able to get all of the entities in the db, with this:

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'point')
    ->entityCondition('bundle', 'point');
$result = $query->execute();

But when I add a fieldCondition, to make sure I only get the one single entity I want, I'll get an empty array back.

It looks like this:

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'point')
    ->entityCondition('bundle', 'point')
    ->fieldCondition('field_point_unique_number', 'value', $unique_number, '=');
$result = $query->execute();

Where $unique_number is a textstring. And it's not a typo in the textstring. In the db the field 'field_point_unique_number' is a varchar, but only contains numbers.

Why does the fieldCondition return nothing?

  • What drupal type of field is "field_point_unique_number"? Check database table field_data_field_point_unique_number, what columns does this table contain? – Stefan Korn Apr 26 '17 at 9:31
  • The drupal type of the field 'field_point_unique_number' is 'text'. In the database, the column I'm trying to make the condition on is 'field_point_unique_number' and its type is varchar. – bqre Apr 26 '17 at 10:02
  • The code is correct for the configuration you described, check the data in $unique_number is what you expect, and the same for the data in the database (make sure there are no leading/trailing spaces, etc) See drupal.stackexchange.com/questions/36542/debug-entityfieldquery for suggestions on seeing the generated query string so you can check for anomalies there too – Clive Apr 26 '17 at 10:17
  • In the database the table should be named "field_data_field_point_unique_number" and there should be a column named "field_point_unique_number_value". You said the column is named "field_point_unique_number". Please be exact about the terms like "table" and "column" and check this. – Stefan Korn Apr 26 '17 at 10:27
  • You are right about that Stefan. The column is called "field_point_unique_number_value". I wrote that wrong. I'll try to check that Clive – bqre Apr 26 '17 at 10:31
-1

I hadn't checked it for trailing spaces. So using trim() on $unique_number did the trick. Thanks for leading me the right way Clive!

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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