diff --git a/Frameworks/Database/Extensions/Article+Database.swift b/Frameworks/Database/Extensions/Article+Database.swift index ef977b975..61367b0d8 100644 --- a/Frameworks/Database/Extensions/Article+Database.swift +++ b/Frameworks/Database/Extensions/Article+Database.swift @@ -114,6 +114,28 @@ extension Article: DatabaseObject { return articleID } } + + public func relatedObjectsWithName(_ name: String) -> [DatabaseObject]? { + + switch name { + case RelationshipName.authors: + return databaseObjectArray(with: authors) + case RelationshipName.tags: + return databaseObjectArray(with: tags) + case RelationshipName.attachments: + return databaseObjectArray(with: attachments) + default: + return nil + } + } + + private func databaseObjectArray(with objects: Set?) -> [DatabaseObject]? { + + guard let objects = objects else { + return nil + } + return Array(objects) + } } extension Set where Element == Article {