Answers.Body: <p>When you install Entityreference, you get a Views Display, 'Entityreference'</p>
  
  <p>You can create a Entityreference view, and use that View to choose what the options are for your entityreference field widget. </p>
  
  <p>In this view you can sort, and get your sort order that way. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-14T03:11:44.880Z
Answers.LastActivityDate: 2017-01-14T03:11:44.880Z
Answers.UserDisplayName: jackrabbithanna
Body: <p>I'd like to link a Drupal node (e.g. content type = 'event' with some custom fields in Drupal) to a CiviCRM event via an entity reference field. </p>
  
  <p>The use case is that there are some events that don't require registration, but some that do, but we want them all to show in the same Events list with the same theming options (these will be pulled in various places on the site in various ways, not just in a calendar list). So: we create all the events in Drupal, and for the ones with registration options, we set up a parallel event in CiviCRM which is linked to the Drupal event by the entity reference field I mentioned at the outset, and we would link with a registration button from the Drupal event directly to the CiviCRM event registration page if there was an entity entered.</p>
  
  <p>I've installed CiviCRM Entity and managed to add a field of type 'entity reference' to the Drupal event node. </p>
  
  <p><a href="https://i.sstatic.net/YXEIY.jpg" rel="noreferrer"><img src="https://i.sstatic.net/YXEIY.jpg" alt="CiviEvent entity reference field"></a></p>
  
  <p>I can tell it that this is a CiviCRM event, and asked it to sort on the event's start date in descending order, so that new events would be at the top. </p>
  
  <p><a href="https://i.sstatic.net/ay883.jpg" rel="noreferrer"><img src="https://i.sstatic.net/ay883.jpg" alt="Field settings"></a></p>
  
  <p>When trying to edit the field (or create an event node if I just leave the field untouched), I get this:</p>
  
  <p><code>PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'civicrm_event.event_start_date' in 'order clause': SELECT civicrm_event.id AS entity_id, :entity_type AS entity_type, NULL AS revision_id, :bundle AS bundle FROM {civicrm_event} civicrm_event ORDER BY civicrm_event.event_start_date DESC; Array ( [:entity_type] =&gt; civicrm_event [:bundle] =&gt; civicrm_event ) in EntityFieldQuery-&gt;execute() (line 1192 of /home/public_html/includes/entity.inc).</code></p>
  
  <p>It looks like the column name in the database should actually be 'civicrm_event.start_date' -- am I right? I grepped in the civicrm_entity folder and didn't see any references to 'event_start_date' in the code, so where should I look next?</p>
  
  <p><strong>UPDATE:</strong> As a temporary fix, if I disable sorting it works as expected.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-06-12T03:51:09.273Z
Comments.Text: Laryn - is the outcome on your drupal node that you have a link eg register that goes to the registration page of civicrm - if so did you do more than set the Field Display to 'link label to entity reference'? I am just getting the event id with no link - should throw in as a new question i guess
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-06-13T02:13:44.460Z
Comments.Text: @petednz-fuzion We ended up doing a little massaging on this field (eg. in views, and also in the node template) to generate a link/button that goes straight to the register page.
Comments.UserDisplayName: Laryn
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-06-13T05:40:24.663Z
Comments.Text: k. thanks. on the site we have to do this on they are using a tpl for event content type otherwise i would have done via views too.
Comments.UserDisplayName: petednz - fuzion
Tags: <drupal><civicrm-entity><entity-reference>
Title: Sort issue with CiviCRM Entity Reference on a Drupal node
ThreadText: # Sort issue with CiviCRM Entity Reference on a Drupal node
  
  (Asked by: username_0 on 2015-08-11)
  
  I'd like to link a Drupal node (e.g. content type = 'event' with some custom fields in Drupal) to a CiviCRM event via an entity reference field.
  
  The use case is that there are some events that don't require registration, but some that do, but we want them all to show in the same Events list with the same theming options (these will be pulled in various places on the site in various ways, not just in a calendar list). So: we create all the events in Drupal, and for the ones with registration options, we set up a parallel event in CiviCRM which is linked to the Drupal event by the entity reference field I mentioned at the outset, and we would link with a registration button from the Drupal event directly to the CiviCRM event registration page if there was an entity entered.
  
  I've installed CiviCRM Entity and managed to add a field of type 'entity reference' to the Drupal event node.
  
  [![CiviEvent entity reference field](https://i.sstatic.net/YXEIY.jpg)](https://i.sstatic.net/YXEIY.jpg)
  
  I can tell it that this is a CiviCRM event, and asked it to sort on the event's start date in descending order, so that new events would be at the top.
  
  [![Field settings](https://i.sstatic.net/ay883.jpg)](https://i.sstatic.net/ay883.jpg)
  
  When trying to edit the field (or create an event node if I just leave the field untouched), I get this:
  
  `PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'civicrm_event.event_start_date' in 'order clause': SELECT civicrm_event.id AS entity_id, :entity_type AS entity_type, NULL AS revision_id, :bundle AS bundle FROM {civicrm_event} civicrm_event ORDER BY civicrm_event.event_start_date DESC; Array ( [:entity_type] => civicrm_event [:bundle] => civicrm_event ) in EntityFieldQuery->execute() (line 1192 of /home/public_html/includes/entity.inc).`
  
  It looks like the column name in the database should actually be 'civicrm\_event.start\_date' -- am I right? I grepped in the civicrm\_entity folder and didn't see any references to 'event\_start\_date' in the code, so where should I look next?
  
  **UPDATE:** As a temporary fix, if I disable sorting it works as expected.
  
  **Tags:** drupal, civicrm-entity, entity-reference
  
  > **Comments:**
  > **username_1**: username_0 - is the outcome on your drupal node that you have a link eg register that goes to the registration page of civicrm - if so did you do more than set the Field Display to 'link label to entity reference'? I am just getting the event id with no link - should throw in as a new question i guess  
  > **username_0**: @username_1 We ended up doing a little massaging on this field (eg. in views, and also in the node template) to generate a link/button that goes straight to the register page.  
  > **username_1**: k. thanks. on the site we have to do this on they are using a tpl for event content type otherwise i would have done via views too.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2017-01-14. Score: 1
  
  When you install Entityreference, you get a Views Display, 'Entityreference'
  
  You can create a Entityreference view, and use that View to choose what the options are for your entityreference field widget.
  
  In this view you can sort, and get your sort order that way.
  
  
  ---
  
  