0

I want get several entries of database. Im a entityfieldquery novice and I misunderstand how I do for get several results who contain certain fields (here, the fields that interest me are : delta, field_top_value and field_top_revision).

enter image description here

By example, I try this code :

$query = new EntityFieldQuery();
$query
    ->entityCondition('entity_id',$nid_device)
    ->entityCondition('entity_type','node');
$result = $query->execute();
dpm($result); //show just one only node...but I would like get the five entries, with field "delta, field_top_value and field_top_revision_id"

I "tried" to read the documentation, but my english reading isn't very good, and I don't find example for my case..

Thanks for help !

2
  • Is there any chance you can get someone who speaks English a bit better to help you re-phrase your question? It's really hard to understand what you're asking, but I'm almost positive there's an easy answer to this. Just need to know what you're asking exactly :)
    – Clive
    Commented Jul 22, 2014 at 14:49
  • sorry sorry x) with the entityfieldquery, I want get several results and no one only result (with my actually code) And I don't understand how I can select some field in my entityFieldQuery (I would like select "delta", "field_top_value" and "field_top_revision" in my case) As you can see (the screenshoot), Ill get five results. Commented Jul 22, 2014 at 14:55

3 Answers 3

0

Whenever you load data by entityfieldquery(), then it will return you everything in term of node.

  1. Here entity_id from table and nid of node is same
  2. vid parameter in node is same as revision_id in the table
  3. delta specifies multiple value saved w.r.t a particular field e.g. a field category with table field_data_field_category has multiple values testcategory1 ,testcategory2.

Then it will saved in the database as delta 0 for testcategory1 and 1 for testcategory2.

And when it will be returned in node all values are assembled to show in the particular field w.r.t which it belongs in the form of array.

Also you can load the node data separately by node_load() function by passing entity_id/node id to load all data w.r.t that particular node in assembled mode.

1

The table in your screenshot is a field table. It stores field data for entities, for both multiple and single cardinality fields.

When you use an EntityFieldQuery, you're querying for entities, not fields. It wouldn't make sense for you to receive data for anything else.

The connection you need to encourage your brain to make is that the fields are attached to the entities. So, if you want to know about multiple field values for a node, you just need to go and get them:

// Keep track of the delta, you mentioned you wanted it...
$delta = 0;
foreach (field_get_items('node', $node, 'field_foo') as $item) {
  $field_value = $item['value'];

  $delta++;
}

If that isn't what you're looking for, then EntityFieldQuery probably isn't the tool for the job. If that's the case, and you're using MySQL as the storage backend for fields, I'd recommend manually querying the field_data_field_foo table to get what you're after directly.

7
  • I don't think its a good solution because the delta maybe modify by differents ways (another module by example..) So, I think the delta don't start all time at 0 =) But maybe im wrong ! Commented Jul 22, 2014 at 16:11
  • Yep, you're wrong ;) the delta always starts at zero, assuming the field API had been used correctly
    – Clive
    Commented Jul 22, 2014 at 16:18
  • the delta isn't the weight ? if I set a weight equal to -1 via the ui, the delta in database will equal to -1 no ? it's just curiosity =) Commented Jul 22, 2014 at 17:50
  • Sure, if you change database values manually, but why would you be doing that? That's what the API is for, so you don't end up unintentionally introducing inconsistencies in the data...before they're saved, field elements are run through _field_filter_items() to filter out empty items. That function returns them with array_values(), effectively resetting the array keys to zero-based again, so you can count on the delta always starting at zero :)
    – Clive
    Commented Jul 22, 2014 at 17:59
  • 1
    @Clive I'm with you; there's a touch of ambiguity to UI in a question that features a screenshot of phpMyAdmin and talks about editing entities!
    – Andy
    Commented Jul 24, 2014 at 10:08
0

Your code is looking for a specific node with a specific nid. nid or entity_id is a unique key. Use different properties to query your entities.

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.