Answers.Body: <p>Your query seems a bit off to me. Focussing just on the portion of it that retrieves the employers of the logged in user wouldn't you have something like:
  Select employer.id, employer.display_name from
  civicrm_contact employer inner join
  civicrm_relationship r on r.contact_id_b=employer.id
  where r.contact_id_a=$current_contact_id limit 0,10;</p>
  
  <p>(If your user isn't logged in, then I would just drop the where clause to populate the select widget with all employer orgs.)</p>
  
  <p>IIRC the employer is the b contact for the relationship, not the a - might want to check that.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-22T20:28:16.290Z
Answers.Text: Contact A is set as the logged in user as far as I can see from the fields in the displays. I placed organisation name as a field so that I could re-write Contact ID B to display the name of the organisation as I have not found a "Contact B display Name" field at all under CiviCRM Relationships or Contacts. Our original development was built using a custom organisation other than employer (as the users were not employees)
Answers.UserDisplayName: Darren Whittenham-Gray
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-19T05:51:19.383Z
Answers.LastActivityDate: 2016-03-19T06:00:38.540Z
Answers.LastEditDate: 2016-03-19T06:00:38.540Z
Answers.UserDisplayName: Joe Murray
Body: <p>What I want to do is allow content authors to associate their news stories to their organisations.</p>
  
  <p>I currently expose the organisations as an auto-complete field, however the target is for the author to not be able to select any organisation except their own.</p>
  
  <p>I installed <a href="https://www.drupal.org/project/entityreference_view_widget" rel="nofollow" title="Entity Reference View">Entity Reference View</a> as this appeared to be the way forward and created the following query for it </p>
  
  <pre><code>    SELECT civicrm_contact.id AS id, civicrm_contact.display_name AS civicrm_contact_display_name, civicrm_relationship.contact_id_b AS civicrm_relationship_contact_id_b, civicrm_relationship.relationship_type_id AS civicrm_relationship_relationship_type_id, civicrm_contact.organization_name AS civicrm_contact_organization_name
  FROM 
  {civicrm_contact} civicrm_contact
  LEFT JOIN {civicrm_relationship} civicrm_relationship ON civicrm_contact.id = civicrm_relationship.contact_id_a
  INNER JOIN {field_data_field_test_member_station} field_data_field_test_member_station ON civicrm_relationship.id = field_data_field_test_member_station.field_test_member_station_target_id AND (field_data_field_test_member_station.entity_type = 'node' AND field_data_field_test_member_station.deleted = '0')
  INNER JOIN {node} field_test_member_station_civicrm_relationship ON field_data_field_test_member_station.entity_id = field_test_member_station_civicrm_relationship.nid
  WHERE (( (civicrm_relationship.relationship_type_id IN  ('17')) ))
  LIMIT 10 OFFSET 0
  </code></pre>
  
  <p>As an Entity Reference AND as an Entity Reference View Widget, but neither worked (contact a is the author contact, b is the organisation, field_test_member..... is the organisation)</p>
  
  <p>Am I heading into this the wrong way? Should I just build a webform and a node creation rule?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-17T22:02:30.327Z
Comments.Text: I was about to offer that final suggestion. You can make 'webform' apply to any 'content type' I believe, so it may work better to do that if that permits you to then pull the value of that field in as a field on to your node.
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-17T22:41:07.497Z
Comments.Text: On a recent non-civi project I struggled to get Webform to create a node with Rules - there was a specific bug preventing it, and I ended up writing a custom module. Good luck though!
Comments.UserDisplayName: JohnFF
Tags: <drupal-views><relationships>
Title: How can I include CiviCRM relationships to node creations screens?
ThreadText: # How can I include CiviCRM relationships to node creations screens?
  
  (Asked by: username_0 on 2016-03-17)
  
  What I want to do is allow content authors to associate their news stories to their organisations.
  
  I currently expose the organisations as an auto-complete field, however the target is for the author to not be able to select any organisation except their own.
  
  I installed [Entity Reference View](https://www.drupal.org/project/entityreference_view_widget "Entity Reference View") as this appeared to be the way forward and created the following query for it
  
  ```
      SELECT civicrm_contact.id AS id, civicrm_contact.display_name AS civicrm_contact_display_name, civicrm_relationship.contact_id_b AS civicrm_relationship_contact_id_b, civicrm_relationship.relationship_type_id AS civicrm_relationship_relationship_type_id, civicrm_contact.organization_name AS civicrm_contact_organization_name
  FROM 
  {civicrm_contact} civicrm_contact
  LEFT JOIN {civicrm_relationship} civicrm_relationship ON civicrm_contact.id = civicrm_relationship.contact_id_a
  INNER JOIN {field_data_field_test_member_station} field_data_field_test_member_station ON civicrm_relationship.id = field_data_field_test_member_station.field_test_member_station_target_id AND (field_data_field_test_member_station.entity_type = 'node' AND field_data_field_test_member_station.deleted = '0')
  INNER JOIN {node} field_test_member_station_civicrm_relationship ON field_data_field_test_member_station.entity_id = field_test_member_station_civicrm_relationship.nid
  WHERE (( (civicrm_relationship.relationship_type_id IN  ('17')) ))
  LIMIT 10 OFFSET 0
  
  ```
  
  As an Entity Reference AND as an Entity Reference View Widget, but neither worked (contact a is the author contact, b is the organisation, field\_test\_member..... is the organisation)
  
  Am I heading into this the wrong way? Should I just build a webform and a node creation rule?
  
  **Tags:** drupal-views, relationships
  
  > **Comments:**
  > **username_1**: I was about to offer that final suggestion. You can make 'webform' apply to any 'content type' I believe, so it may work better to do that if that permits you to then pull the value of that field in as a field on to your node.  
  > **username_2**: On a recent non-civi project I struggled to get Webform to create a node with Rules - there was a specific bug preventing it, and I ended up writing a custom module. Good luck though!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2016-03-19. Score: 1
  
  Your query seems a bit off to me. Focussing just on the portion of it that retrieves the employers of the logged in user wouldn't you have something like:
  Select employer.id, employer.display\_name from
  civicrm\_contact employer inner join
  civicrm\_relationship r on r.contact\_id\_b=employer.id
  where r.contact\_id\_a=$current\_contact\_id limit 0,10;
  
  (If your user isn't logged in, then I would just drop the where clause to populate the select widget with all employer orgs.)
  
  IIRC the employer is the b contact for the relationship, not the a - might want to check that.
  
  > **Comments:**
  > **username_0**: Contact A is set as the logged in user as far as I can see from the fields in the displays. I placed organisation name as a field so that I could re-write Contact ID B to display the name of the organisation as I have not found a "Contact B display Name" field at all under CiviCRM Relationships or Contacts. Our original development was built using a custom organisation other than employer (as the users were not employees)  
  
  ---
  
  