Answers.Body: <p>I think you're talking about the feature whereby you can limit the number of contacts that inherit a relationship, and then create/delete the related memberships when viewing the owner membership:</p>
  <p><a href="https://i.sstatic.net/x3sTh.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/x3sTh.png" alt="enter image description here" /></a></p>
  <p>The code behind 'create' is <a href="https://github.com/civicrm/civicrm-core/blob/5.71/CRM/Member/Form/MembershipView.php#L109-L128" rel="nofollow noreferrer">https://github.com/civicrm/civicrm-core/blob/5.71/CRM/Member/Form/MembershipView.php#L109-L128</a> which basically copies a load of parameters from the owner (parent) membership and creates a new one including the <code>owner_membership_id</code>.  APIv4 <code>Membership.create()</code> lets you specify <code>owner_membership_id</code> so it looks like you should be able to do what you want.</p>
  <p>So far as I know, this feature is not used much so test your create and delete code carefully.</p>
  <p>Since it involves a lot of copying from the owner membership it would be nicer to wrap those up as API actions with their own tests to protect their functionality.  I don't know what happens if for example the owner and inherited memberships have different start and end dates. If you create via the UI, the code sets those to be the same but if you do different things via the API you could run into strange effects.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-14T18:42:36.337Z
Answers.LastActivityDate: 2024-02-14T18:42:36.337Z
Answers.UserDisplayName: Aidan
Body: <p>I have a parent account which can possess multiple memberships. There can be multiple children which inherit one of these membership. I want to be able to choose which child inherits which membership. I know it's possible via the GUI, but is there a way of doing this programmatically? I tried looking at the API browser, but couldn't find anything.</p>
  <p>Thank you!</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-11T20:49:58.560Z
Comments.Text: I can't see how you can do this but also perhaps you could flesh out the workflow a bit more. A more common scenario is that a parent would pay for a membership and the amount they would pay would depend on the number of children they have who also have the assigned Relationship Type to the parent. Ie all the children maybe 'children of', but if you build the Memb Type to use a relationship of 'Child member of' then it would only be the kids with that latter relationship who would inherit
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-17T01:18:42.610Z
Comments.Text: HI! Thank you for your response. I think this would work for our workflow, but how would the price of the membership reflect the amount of relationships. Currently, with our workflow, the user gets put in a pending membership on signup and then are sent the contribution form to pay when they are approved. I was thinking of a price set, but how would I lock in the price to reflect the correct amount of relations? If I used a hook, would the contribution form break if two people tried accessing that form at the same time?
Comments.UserDisplayName: user15536
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-17T19:58:58.327Z
Comments.Text: if the pricing is per child then yes it gets trickier. if i was doing this, and since i use Drupal mostly, i would do this via Webform_CiviCRM which can handle that side of things. not sure what other CMS can offer
Comments.UserDisplayName: petednz - fuzion
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-02-17T22:51:09.137Z
Comments.Text: Unfortunately, I am using WordPress. I guess the only way is to create a custom contribution form then maybe?
Comments.UserDisplayName: user15536
Tags: <civimember><relationships>
Title: Giving membership via relationship to specific contact
ThreadText: # Giving membership via relationship to specific contact
  
  (Asked by: username_0 on 2024-02-10)
  
  I have a parent account which can possess multiple memberships. There can be multiple children which inherit one of these membership. I want to be able to choose which child inherits which membership. I know it's possible via the GUI, but is there a way of doing this programmatically? I tried looking at the API browser, but couldn't find anything.
  
  Thank you!
  
  **Tags:** civimember, relationships
  
  > **Comments:**
  > **username_1**: I can't see how you can do this but also perhaps you could flesh out the workflow a bit more. A more common scenario is that a parent would pay for a membership and the amount they would pay would depend on the number of children they have who also have the assigned Relationship Type to the parent. Ie all the children maybe 'children of', but if you build the Memb Type to use a relationship of 'Child member of' then it would only be the kids with that latter relationship who would inherit  
  > **username_0**: HI! Thank you for your response. I think this would work for our workflow, but how would the price of the membership reflect the amount of relationships. Currently, with our workflow, the user gets put in a pending membership on signup and then are sent the contribution form to pay when they are approved. I was thinking of a price set, but how would I lock in the price to reflect the correct amount of relations? If I used a hook, would the contribution form break if two people tried accessing that form at the same time?  
  > **username_1**: if the pricing is per child then yes it gets trickier. if i was doing this, and since i use Drupal mostly, i would do this via Webform_CiviCRM which can handle that side of things. not sure what other CMS can offer  
  > **username_0**: Unfortunately, I am using WordPress. I guess the only way is to create a custom contribution form then maybe?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2024-02-14. Score: 1
  
  I think you're talking about the feature whereby you can limit the number of contacts that inherit a relationship, and then create/delete the related memberships when viewing the owner membership:
  
  [![enter image description here](https://i.sstatic.net/x3sTh.png)](https://i.sstatic.net/x3sTh.png)
  
  The code behind 'create' is <https://github.com/civicrm/civicrm-core/blob/5.71/CRM/Member/Form/MembershipView.php#L109-L128> which basically copies a load of parameters from the owner (parent) membership and creates a new one including the `owner_membership_id`. APIv4 `Membership.create()` lets you specify `owner_membership_id` so it looks like you should be able to do what you want.
  
  So far as I know, this feature is not used much so test your create and delete code carefully.
  
  Since it involves a lot of copying from the owner membership it would be nicer to wrap those up as API actions with their own tests to protect their functionality. I don't know what happens if for example the owner and inherited memberships have different start and end dates. If you create via the UI, the code sets those to be the same but if you do different things via the API you could run into strange effects.
  
  
  ---
  
  