diff --git a/CRM/Member/DAO/MembershipType.php b/CRM/Member/DAO/MembershipType.php
index 7ad60e02cce..01c5b69e662 100644
--- a/CRM/Member/DAO/MembershipType.php
+++ b/CRM/Member/DAO/MembershipType.php
@@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Member/MembershipType.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:b166299a8c5c846f5cb4f34fd6532f55)
+ * (GenCodeChecksum:f0aee394cff9d0c7eee0245021a4a3e1)
*/
/**
@@ -405,6 +405,7 @@ public static function &fields() {
'entity' => 'MembershipType',
'bao' => 'CRM_Member_BAO_MembershipType',
'localizable' => 0,
+ 'serialize' => self::SERIALIZE_SEPARATOR_TRIMMED,
],
'relationship_direction' => [
'name' => 'relationship_direction',
@@ -417,6 +418,7 @@ public static function &fields() {
'entity' => 'MembershipType',
'bao' => 'CRM_Member_BAO_MembershipType',
'localizable' => 0,
+ 'serialize' => self::SERIALIZE_SEPARATOR_TRIMMED,
],
'max_related' => [
'name' => 'max_related',
diff --git a/tests/phpunit/CRM/Contact/BAO/RelationshipTest.php b/tests/phpunit/CRM/Contact/BAO/RelationshipTest.php
index 382f404f96a..7b3ed5bcece 100644
--- a/tests/phpunit/CRM/Contact/BAO/RelationshipTest.php
+++ b/tests/phpunit/CRM/Contact/BAO/RelationshipTest.php
@@ -206,4 +206,69 @@ public function getRelationshipTypeDuplicates() {
return $data;
}
+ /**
+ * Test that two similar memberships are not created for two relationships
+ *
+ * @throws \CRM_Core_Exception
+ */
+ public function testSingleMembershipForTwoRelationships() {
+ $individualID = $this->individualCreate(['display_name' => 'Individual A']);
+ $organisationID = $this->organizationCreate(['organization_name' => 'Organization B']);
+ $membershipOrganisationID = $this->organizationCreate(['organization_name' => 'Membership Organization']);
+ $orgToPersonTypeId1 = $this->relationshipTypeCreate(['name_a_b' => 'Inherited_Relationship_1_A_B', 'name_b_a' => 'Inherited_Relationship_1_B_A']);
+ $orgToPersonTypeId2 = $this->relationshipTypeCreate(['name_a_b' => 'Inherited_Relationship_2_A_B', 'name_b_a' => 'Inherited_Relationship_2_B_A']);
+
+ $membershipType = $this->callAPISuccess('MembershipType', 'create', [
+ 'member_of_contact_id' => $membershipOrganisationID,
+ 'financial_type_id' => 'Member Dues',
+ 'duration_unit' => 'year',
+ 'duration_interval' => 1,
+ 'period_type' => 'rolling',
+ 'name' => 'Inherited Membership',
+ 'relationship_type_id' => [$orgToPersonTypeId1, $orgToPersonTypeId2],
+ 'relationship_direction' => ['b_a', 'a_b'],
+ ]);
+ $membershipType = $this->callAPISuccessGetSingle('MembershipType', ['id' => $membershipType['id']]);
+ // Check the metadata worked....
+ $this->assertEquals([$orgToPersonTypeId1, $orgToPersonTypeId2], $membershipType['relationship_type_id']);
+ $this->assertEquals(['b_a', 'a_b'], $membershipType['relationship_direction']);
+
+ $this->callAPISuccess('Membership', 'create', [
+ 'membership_type_id' => $membershipType['id'],
+ 'contact_id' => $organisationID,
+ ]);
+
+ $relationshipOne = $this->callAPISuccess('Relationship', 'create', [
+ 'contact_id_a' => $individualID,
+ 'contact_id_b' => $organisationID,
+ 'relationship_type_id' => $orgToPersonTypeId1,
+ ]);
+ $relationshipTwo = $this->callAPISuccess('Relationship', 'create', [
+ 'contact_id_a' => $individualID,
+ 'contact_id_b' => $organisationID,
+ 'relationship_type_id' => $orgToPersonTypeId2,
+ ]);
+
+ /*
+ * @todo this section not yet working due to bug in would-be-tested code.
+ $this->callAPISuccessGetCount('Membership', ['contact_id' => $individualID], 1);
+ $relationshipTwo['is_active'] = 0;
+ $this->callAPISuccess('Relationship', 'create', $relationshipTwo);
+ $this->callAPISuccessGetCount('Membership', ['contact_id' => $individualID], 1);
+ $relationshipOne['is_active'] = 0;
+ $this->callAPISuccess('Relationship', 'create', $relationshipOne);
+ $this->callAPISuccessGetCount('Membership', ['contact_id' => $individualID], 0);
+ $relationshipOne['is_active'] = 1;
+ $this->callAPISuccess('Relationship', 'create', $relationshipOne);
+ $this->callAPISuccessGetCount('Membership', ['contact_id' => $individualID], 1);
+ $relationshipTwo['is_active'] = 1;
+ $this->callAPISuccess('Relationship', 'create', $relationshipTwo);
+ $this->callAPISuccessGetCount('Membership', ['contact_id' => $individualID], 1);
+ $this->callAPISuccess('Relationship', 'delete', ['id' => $relationshipTwo['id']]);
+ $this->callAPISuccessGetCount('Membership', ['contact_id' => $individualID], 1);
+ $this->callAPISuccess('Relationship', 'delete', ['id' => $relationshipOne['id']]);
+ $this->callAPISuccessGetCount('Membership', ['contact_id' => $individualID], 0);
+ */
+ }
+
}
diff --git a/xml/schema/Member/MembershipType.xml b/xml/schema/Member/MembershipType.xml
index a71afd51a7f..47a62305484 100644
--- a/xml/schema/Member/MembershipType.xml
+++ b/xml/schema/Member/MembershipType.xml
@@ -189,6 +189,7 @@
64
FK to Relationship Type ID
1.5
+ SEPARATOR_TRIMMED
relationship_type_id
@@ -207,6 +208,7 @@
varchar
128
1.7
+ SEPARATOR_TRIMMED
max_related