On Tuesday, December 25, 2018 at 7:37:58 AM UTC-8, genc wrote:
>
> Hi Jeremy,
>
> When I do this:
>
> class User < Sequel::Model
>  ...
> end
>
> user = User.new
> user.properties = { name: 'Genc', age: 42 }  # or ':name =>..., '
> user.save
>
> #try to fetch assigned data
> user.properties[:name] # => Genc
> user.properties[:age] # => 42
>
>
> However, If I fetch that data later or again like this:
>
> # fetch user 1
> user = User[1]
>
> user.properties[:name] # => nil
> user.properties[:age] # => nil
> # Try string keys
> user.properties['name'] # => Genc
> user.properties['age'] # => 42
>
>
> As you can see I did not use :symbol because the keys are strings not 
> symbols. How can I make Sequel *globally *fetch all keys as symbolic?
>

This is expected behavior.  Sequel returns rows as symbol-keyed hashes.  
However, json and jsonb fields use string keys, because symbols do not 
round trip through JSON (JSON doesn't support symbols).  There currently is 
no option for symbol-keyed json/jsonb fields, and no plans to add such an 
option.  However, if you can probably get the behavior you want by 
overriding some methods in the pg_json extension.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to