Answers.Body: <p>I can think of two approaches.</p>
  
  <p>One - instead of <code>hook_civicrm_post</code>, use use <code>hook_civicrm_postProcess</code>, like you describe, to grab the Contact A id.</p>
  
  <p>Two - use <code>hook_civicrm_post</code> on the Membership object rather than the Contribution object.  This should get you Contact B's id.  You can then use an API <code>get</code> to look up the most recently created Relationship for Contact B, which should be Contact A.  Then use an API <code>create</code> to create your new Relationship.</p>
  
  <p>I'd probably go with option two, personally.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-21T22:29:46.717Z
Answers.Text: Thanks a ton, Jon, option two is exactly what I needed to determine Contact A. Appreciate the help!
Answers.UserDisplayName: schatz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-20T01:49:30.797Z
Answers.LastActivityDate: 2015-09-20T01:49:30.797Z
Answers.UserDisplayName: Jon G - Megaphone Tech
Body: <p>Having trouble with memberships created on behalf of an organization that need a different relationship type than Employee of/Employer. I have a suspicion I'm simply approaching it the wrong way.</p>
  
  <p>We have Individual and Institutional membership types. For Institutional memberships, there is a relationship type set of Designate of/Designator. The contribution form for purchasing Institutional memberships uses its own price set and price options set correctly to create that membership.</p>
  
  <p>Included in this contribution form are the 'On Behalf of Organization' profile and the WordPress user account form.</p>
  
  <p>When a new user purchases an Institutional membership the following get created:</p>
  
  <ul>
  <li>New Individual contact (Contact A).</li>
  <li>New Organization contact (Contact B). </li>
  <li>A new Institutional membership for the Organization. </li>
  <li>A relationship of Employee of/Employer between Contact A and Contact B.</li>
  </ul>
  
  <p>Missing from these is the Designate relationship so that Contact A also inherits the membership. I'm not sure why this relationship isn't created despite the membership type requiring it.</p>
  
  <p>The solution I'm pursuing now relies on implementing <code>hook_civicrm_post</code> in a plugin and doing some lookups with the API based on the membership object to create this relationship after the fact. </p>
  
  <p>However it seems to be that nothing about Contact A (individual) who made the contribution on behalf of Contact B is available beyond the employee/employer relationship - which might exist for any number of other employees that are not the designate. <a href="https://civicrm.stackexchange.com/questions/6241/existing-organizations-getting-updated-when-new-person-signs-up-with-the-same-or">I especially want to avoid this potential issue</a>.</p>
  
  <p>My expectation would be to find this in that particular Contribution object but no dice. Right now I'm thinking either getting Contact A's contact_id from the pre hook or from the form submission itself.</p>
  
  <p>Is this behaviour a bug or am I missing an obvious setting? If not, surely there is a better way via the API?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-09-21T22:31:25.157Z
Comments.Text: A note for others attempting this, you'll need a condition to check that your hook function isn't also run for the second membership created by this new relationship.
Comments.UserDisplayName: schatz
Tags: <wordpress><civimember><relationships>
Title: Creating other relationships for memberships on behalf of an organization
ThreadText: # Creating other relationships for memberships on behalf of an organization
  
  (Asked by: username_0 on 2015-09-19)
  
  Having trouble with memberships created on behalf of an organization that need a different relationship type than Employee of/Employer. I have a suspicion I'm simply approaching it the wrong way.
  
  We have Individual and Institutional membership types. For Institutional memberships, there is a relationship type set of Designate of/Designator. The contribution form for purchasing Institutional memberships uses its own price set and price options set correctly to create that membership.
  
  Included in this contribution form are the 'On Behalf of Organization' profile and the WordPress user account form.
  
  When a new user purchases an Institutional membership the following get created:
  
  * New Individual contact (Contact A).
  * New Organization contact (Contact B).
  * A new Institutional membership for the Organization.
  * A relationship of Employee of/Employer between Contact A and Contact B.
  
  Missing from these is the Designate relationship so that Contact A also inherits the membership. I'm not sure why this relationship isn't created despite the membership type requiring it.
  
  The solution I'm pursuing now relies on implementing `hook_civicrm_post` in a plugin and doing some lookups with the API based on the membership object to create this relationship after the fact.
  
  However it seems to be that nothing about Contact A (individual) who made the contribution on behalf of Contact B is available beyond the employee/employer relationship - which might exist for any number of other employees that are not the designate. [I especially want to avoid this potential issue](https://civicrm.stackexchange.com/questions/6241/existing-organizations-getting-updated-when-new-person-signs-up-with-the-same-or).
  
  My expectation would be to find this in that particular Contribution object but no dice. Right now I'm thinking either getting Contact A's contact\_id from the pre hook or from the form submission itself.
  
  Is this behaviour a bug or am I missing an obvious setting? If not, surely there is a better way via the API?
  
  **Tags:** wordpress, civimember, relationships
  
  > **Comments:**
  > **username_0**: A note for others attempting this, you'll need a condition to check that your hook function isn't also run for the second membership created by this new relationship.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-09-20. Score: 3 | Accepted answer
  
  I can think of two approaches.
  
  One - instead of `hook_civicrm_post`, use use `hook_civicrm_postProcess`, like you describe, to grab the Contact A id.
  
  Two - use `hook_civicrm_post` on the Membership object rather than the Contribution object. This should get you Contact B's id. You can then use an API `get` to look up the most recently created Relationship for Contact B, which should be Contact A. Then use an API `create` to create your new Relationship.
  
  I'd probably go with option two, personally.
  
  > **Comments:**
  > **username_0**: Thanks a ton, Jon, option two is exactly what I needed to determine Contact A. Appreciate the help!  
  
  ---
  
  