gpt4 book ai didi

ruby-on-rails - ActiveRecord/Ruby on Rails 中 update_all() 的返回值是多少?

转载 作者:行者123 更新时间:2023-12-03 17:34:51 25 4
gpt4 key购买 nike

Ruby on Rails 和 ActiveRecord 文档、Google 和 StackOverflow 密谋地对 update_all() 的返回值保持沉默

update_all() 返回什么?

  • 记录数?
  • 成功状态?
  • 更新记录的ID?
  • 最佳答案

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

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

    it 'returns number of records updated' do
    expect(User.where(last_name: 'Smitty')
    .update_all(last_name: 'Smith')).to eq 2
    end
    end
    产量:
    User
    .update_all
    returns number of records updated

    Finished in 0.1245 seconds (files took 13.17 seconds to load)
    1 example, 0 failures

    关于ruby-on-rails - ActiveRecord/Ruby on Rails 中 update_all() 的返回值是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52189303/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com