On Monday, May 28, 2012 12:02:12 PM UTC-7, Geraldo Lopes de Souza wrote: > > It would be nice if set_fields were more forgiving with this. Kind of > hash = hash.values if hash < Sequel::Model >
I don't agree. You shouldn't be passing model objects to it, just hashes. Unless the API specifically says that you can use model objects, I think adding specific code to accept them is a bad idea. > I'm using the awesome to_json(:only => [:field1, :field2]) in cases > like at insertion where I have a full instance on the server, but just > want to return the fields the client needs to access. > > I've looked the from_json (plugin) code and it's merely calls set. > def from_json(json) > set(JSON.parse(json)) > end > > It would be nice if it used set_fields making it more secure like > to_json with :only parameters, this way I could call : > instance.from_json(data, [:field1, :field2]) and I would have all > functionality packed in a call. > That makes sense to me, though I'd probably use an API like: instance.from_json(data, :fields=>[:field1, :field2]) An options hash based API is easier to extend in the future. If you want to work on adding support for that, I won't have a problem merging such a patch. Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/sequel-talk/-/If8cEgfJ3gQJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
