Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update via JSON #13

Open
danielpclark opened this issue Apr 30, 2017 · 4 comments
Open

Update via JSON #13

danielpclark opened this issue Apr 30, 2017 · 4 comments

Comments

@danielpclark
Copy link
Collaborator

How do you update an existing model from JSON? I can't seem to figure out the use of from_json and update with this.

@tbrand
Copy link
Collaborator

tbrand commented Apr 30, 2017

Currently, Topaz doesn't have def to_json and def from_json. (Just have def self.to_json and def self.from_json via JSON.mapping)
But it is a really necessary feature to be implemented...

@danielpclark danielpclark changed the title Question: Update via JSON Update via JSON Apr 30, 2017
@tbrand
Copy link
Collaborator

tbrand commented May 1, 2017

What I thought is somehing like this.

class JsonSample < Topaz::Model
    columns(name: String)
end

JsonSample.create(name: "OK")

json_sample = JsonSample.find(1) # The name of this is "OK"
json_sample.update(%({"name": "NG"}))

puts JsonSample.find(1).name # => "NG"

@danielpclark
Copy link
Collaborator Author

danielpclark commented May 1, 2017

Yes, I like it. I've been trying to think what kind of Object it would need to be JSON::Any or maybe JSON::Puller for the update method… since having a String type doesn't indicate to the update method that it's in JSON format.

Also I've been trying to think of how it would work (how to implement it). I'd have to experiment a bit before I can come up with an implementation.

@tbrand
Copy link
Collaborator

tbrand commented May 5, 2017

I've invited you as Topaz collaborator.
If you are OK, please commit and maintain this repository:+1:

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

No branches or pull requests

2 participants