Skip to content
This repository has been archived by the owner on Jan 25, 2019. It is now read-only.

Sorry for posting this as issue. #110

Closed
sachin-sat opened this issue Sep 23, 2016 · 9 comments
Closed

Sorry for posting this as issue. #110

sachin-sat opened this issue Sep 23, 2016 · 9 comments

Comments

@sachin-sat
Copy link

Hi, I'm new to swift.

In this project, i just created a subclass for HTTPClient, hit a remote from there and added that client to spine's networkclient. Spine onsuccess closure gives me resources ---> is it correct/process?
And there is no data{[]} in the relationship of the model from my REMOTE API(one to many concept - parent have data and child doesn't have. it has only self links - related and resource link in my case) - Is it possible to get child model's data using those remote links in spine.

Thanks in advance

@wvteijlingen
Copy link
Owner

wvteijlingen commented Sep 26, 2016

If Spine returns the resources, you've probably done it correctly. You only need to subclass HTTPClient if you have specific networking requirements. Usually this is not the case.

Yes, you can get the related resources with a Query by using this initialiser: init(resourceType: T.Type, resourceCollection: ResourceCollection)

@sachin-sat
Copy link
Author

You are the man, thanks dude.
Let me working on them.

cheers.

@sachin-sat
Copy link
Author

sachin-sat commented Sep 28, 2016

Hi Wvteijlingen,
The word 'Persisting' makes me confuse. Spine manages any DB/file writing ?
Shall I store them in my DB? if I store them in the DB means, how can I get related resources with a Query.
I mean that "Should I convert my DB model into resourcecollection"?.
Please advice me if i'm wrong.

Thanks in advance.

@wvteijlingen
Copy link
Owner

No, Spine doesn’t save anything locally. With “persisting" I mean POSTing or PUTting the resource to the server. The Resource class implements NSCoding so you could store the resources locally if you’d like (as a cache for example). But that is something you’d have to do yourself.

On 28 Sep 2016, at 06:30, sachin-sat notifications@github.com wrote:

Hi Wvteijlingen,
The word 'Persisting' makes me confuse. Spine manages any DB/file writing ?
Shall I store them in my DB? if I store them in the DB means, how can I get related resources with a Query.
I should convert my DB model into resourcecollection. Please advice me if i'm wrong.

Thanks in advance.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub #110 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/ABZJN_0g_QlQ3nVMaBZMW3xM8-q4Evjkks5que1WgaJpZM4KEzyE.

@sachin-sat
Copy link
Author

Thanks dude.
The reason for asking about storing is that 'as it needs resourcecollection to make query to get related models, storing the resourcecollection in the db/file and converting them into resourcecollection seems not good, right?'
But I can get the related resources using init with PATH while making Query. it needs full URL Path(https://www.example.com/xx/yy/zz). Doesn't consider the URL path(the base URL while spine init).
Is it proper/seems good?

Please advice me since I'm new to swift.

Thanks in advance

@wvteijlingen
Copy link
Owner

You can store the entire ResourceCollection if you want. You can also store just the URL and use that to initialise a new Query. Storing just the URL takes up less storage space.

@sachin-sat
Copy link
Author

I have a attribute named 'description' in the JSON. As we know, 'description' is pre-defined name to get object's description. So i should use Field name formatters, right?

my code will look like this

public struct AllCapsKeyFormatter: KeyFormatter {
public func format(field: Field) -> String {
if(field.serializedName == "description")
return "description_property" //My object's attribute name
else
return field.serializedName.uppercaseString
}
}

is this correct?
will it cause any slowness in run time as it applies for every fields?

@wvteijlingen
Copy link
Owner

wvteijlingen commented Oct 5, 2016

You do not need to use a KeyFormatter for this. You can simply define a different serialized named as follows:

override class var fields: [Field] {
  return fieldsFromDictionary([
    "description_property": Attribute().serializeAs("description")
  ])
}

The Swift property will now be called description_property, and it will map to a JSON key named description.

@sachin-sat
Copy link
Author

seems great. Thanks buddy.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants