我正在尝试播种一些数据,但我有一个接受哈希的字段。当我执行以下操作时
50.times do
Event.create(
name: Faker::Internet.name,
data: Faker::Lorem.words(4),
uri: Faker::Internet.url
)
end
events = Event.all
我收到一条错误消息,说数据作为一个数组被播种,因为它是一个哈希字段。有解决办法吗?
rake aborted!
Mongoid::Errors::InvalidValue:
Problem:
Value of type Array cannot be written to a field of type Hash
Summary:
Tried to set a value of type Array to a field of type Hash
我尝试执行以下操作:
data: Faker::Lorem.words(4).to_h
但它似乎不起作用。