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
264 stars 109 forks source link

Retrieving more than one relationship #190

Open ratzr15 opened 6 years ago

ratzr15 commented 6 years ago

I'm trying to get more than one relationship using , include

As : "relationship1.relationship1.child,relationship1"

I'm registering the Query for the Resource associated and passing the ResourceID

But only one of the Resource gets loaded.

My Query:

        var query    = Query.init(resourceType: MyResource.self, resourceIDs: ["1111"])
        query.include(relation1.child,relation2)

What am i missing here ?

markst commented 6 years ago

@ratzr15 are you sure this isn't a server side issue?

ratzr15 commented 6 years ago

@markst Nope, I have always had issue accessing more than one relationship. I'm able to load more than one relationship as :var query = Query(resourceType: MyResource.self, resourceCollection: resource.respurce_children!)

But it increases the number of Spine requests for example if have to get resource1.resource1relation,resource2,resource3 I have to make 3 Spine requests to get the relative data.

Any example on how to load more than one relationship would be really appreciated.

ratzr15 commented 6 years ago

@markst Figured it out 🤤

I should be querying relationships as [String]

query.include("relation1.child,relation2,relation3") should be as query.include("relation1.child","relation2","relation3")