Closed jasonenglish closed 8 years ago
Wondering if it's possible to coerce a hash value to a collection of models.
Example (based on the readme "Hash attributes coercion" section): attribute :results, Hash[String => Array[Person]]
attribute :results, Hash[String => Array[Person]]
Given this JSON
{ "element_count": 60, "results": { "2015-04-06": [ { "id": 1, "name": "Jon Snow" } ] } }
I would like to end up with the MyObject results being a hash of String:Array[Person] values. => #<MyObject:0x007f82049c3e38 @element_count=60, @results=>{"2015-04-06"=>[#<Person:0x007f82049c3e38 @id=1, @name=Jon Snow.....]
=> #<MyObject:0x007f82049c3e38 @element_count=60, @results=>{"2015-04-06"=>[#<Person:0x007f82049c3e38 @id=1, @name=Jon Snow.....]
Any ideas on how to achieve this?
Ended up just manually doing the coercion
@jasonenglish any points how did you made that?
Wondering if it's possible to coerce a hash value to a collection of models.
Example (based on the readme "Hash attributes coercion" section):
attribute :results, Hash[String => Array[Person]]
Given this JSON
I would like to end up with the MyObject results being a hash of String:Array[Person] values.
=> #<MyObject:0x007f82049c3e38 @element_count=60, @results=>{"2015-04-06"=>[#<Person:0x007f82049c3e38 @id=1, @name=Jon Snow.....]
Any ideas on how to achieve this?