Skip to content

Commit 85d948c

Browse files
committed
Add Relationship.init() with generics support
1 parent 33d493d commit 85d948c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Sources/CoreModel/Entity.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,21 @@ public extension EntityDescription {
5252
self.init(id: T.entityName, attributes: attributes, relationships: relationships)
5353
}
5454
}
55+
56+
public extension Relationship {
57+
58+
init<Entity, DestinationEntity>(
59+
id: Entity.CodingKeys,
60+
entity: Entity.Type,
61+
destination: DestinationEntity.Type,
62+
type: RelationshipType,
63+
inverseRelationship: DestinationEntity.CodingKeys
64+
) where Entity: CoreModel.Entity, DestinationEntity: CoreModel.Entity {
65+
self.init(
66+
id: PropertyKey(id),
67+
type: type,
68+
destinationEntity: destination.entityName,
69+
inverseRelationship: PropertyKey(inverseRelationship)
70+
)
71+
}
72+
}

0 commit comments

Comments
 (0)