Rails 5ではjsonb
カラムにstore_accessor
で公開されるフィールドを持つ新しい属性APIを使用できますか?例えば`store_accessor`で` attribute`を使用することができます
、私が持っている:
class Item < ApplicationRecord
# ...
store_accessor :metadata, :publication_date
attribute :publication_date, :datetime
end
その後、私はi = Item.new(publication_date: '2012-10-24')
を呼びたい、などのハッシュことmetadata
持っていると思います:{ 'publication_date' => #<DateTimeInstance> }
。
しかし、attribute
コールは強制的に実行されていないようです。
jsonb
列を扱うときに非常に有用であろう一緒にこれらの2つの機能を使用することができることのように思えます。 (なぜ、属性APIが一般的な
array: true
オプションを公開していないのですか?)これはまた、この場合にも非常に便利です)。