update_all()的返回值是多少?

Dav*_*mpy 7 activerecord ruby-on-rails rails-activerecord

ActiveRecord文档,Google和StackOverflow在update_all()的返回值上是阴谋的

update_all()返回什么?

  • 记录数量?
  • 成功状态?
  • 更新记录的ID?

Dav*_*mpy 10

ActiveRecord的update_all()返回更新的记录数.

describe '.update_all' do
  let!(:user1) { create :user }
  let!(:user2) { create :user }
  let!(:user3) { create :user }

  it 'returns number of records updated' do
    expect(User.update_all(last_name: 'Smith')).to eq 3
  end
end
Run Code Online (Sandbox Code Playgroud)

产量:

User
  .update_all
    returns number of records updated

Finished in 0.1245 seconds (files took 13.17 seconds to load)
1 example, 0 failures
Run Code Online (Sandbox Code Playgroud)

  • 也许还发布了文档修复公关?事实上,这些信息看起来应该存在. (5认同)
  • 我站起来,@ SergioTulentsev!我认为这将是一个快速克隆/编辑/推/ PR ...但我从来没有贡献过rails.现在正在设置rails-dev-box ... (2认同)