wvteijlingen / Spine

A Swift library for working with JSON:API APIs. It supports mapping to custom model classes, fetching, advanced querying, linking and persisting.
MIT License
266 stars 109 forks source link

Polymorphic relationship #183

Open rabc opened 7 years ago

rabc commented 7 years ago

What is the best way to define a polymorphic relationship? I created the models and they are inheriting from the same base class, but then how do I define a ToOne relationship?

I tried using the base class, like (where Group is my base class):

override open class var fields: [Field] {
        return fieldsFromDictionary([
            "group": ToOneRelationship(Group.self)
            ])
    }

But then the deserializer gets the resourceType from the base class, even if I register only the child class.

markst commented 7 years ago

@rabc should be achievable using branch on this PR: https://github.com/wvteijlingen/Spine/pull/154