使用 upsert 时未定义的方法 'keys'
undefined method 'keys' when using upsert
我想使用 upsert_all 方法从集合中插入(和更新)记录
在一个简单的查询中,例如:
books = []
10.times do |i|
books << Book.new(name: "book #{i}")
end
Book.upsert_all(books)
但是,我收到以下错误:
.../activemodel-6.1.4.1/lib/active_model/attribute_methods.rb:469:in `method_missing': undefined method `keys' for #<Book id: nil, name: "book 0"> (NoMethodError)
我正在寻找的是能够插入全部或 upsert_all 任意集合作为书籍,例如,如果你能帮助我,我将不胜感激
upsert_all
需要一个哈希数组,而不是 ActiveRecord 对象:
books = []
10.times do |i|
books << { name: "book #{i}" }
end
Book.upsert_all(books)
我想使用 upsert_all 方法从集合中插入(和更新)记录 在一个简单的查询中,例如:
books = []
10.times do |i|
books << Book.new(name: "book #{i}")
end
Book.upsert_all(books)
但是,我收到以下错误:
.../activemodel-6.1.4.1/lib/active_model/attribute_methods.rb:469:in `method_missing': undefined method `keys' for #<Book id: nil, name: "book 0"> (NoMethodError)
我正在寻找的是能够插入全部或 upsert_all 任意集合作为书籍,例如,如果你能帮助我,我将不胜感激
upsert_all
需要一个哈希数组,而不是 ActiveRecord 对象:
books = []
10.times do |i|
books << { name: "book #{i}" }
end
Book.upsert_all(books)