0

I have a node which references another, I want to order the results based on the title of the referenced field title.

I'm using

function listAll(){
  $query = new EntityFieldQuery();
  $entities = $query->entityCondition('entity_type', 'node')
                    ->entityCondition('bundle', 'building')
                    ->fieldOrderBy('field_reference_area', 'title', 'ASC')
                    ->execute();

  $nodes = entity_load('node', array_keys($entities['node']));

  foreach($nodes as $key => $fac){
      dsm($fac);
  } 
}
  • so basically you need to use join to achieve this. – j2r Oct 18 '12 at 18:15
1

I'm afraid this won't be possible using EntityFieldQuery. You could build your own query using db_select() and have full control over it.

You can refer to this post and try to adapt it to fit your needs.

  • thxs !, it seems you are right – mauricio Oct 17 '12 at 14:01
0

You can use join using something like

$query = new EntityFieldQuery();
$entities = $query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'building')
->fieldOrderBy('field_reference_area', 'title', 'ASC')
->addTag('JOINTABLE');
->execute();


And now use this tag to join another table

function MYDMOULE_query_JOINTABLE_alter(QueryAlterableInterface $query) {
$query->join('reference_table', 'r', 'r.nid = node.field_referencefield_value');
}

This is just a sample example. Try to modified it with your need. :)

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.