hel*_*llo 7 database boolean ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2
如果我的数据库设置为false,那么更新数据库中的布尔值是什么?
我可以在控制台上做到:
>> u = User.find_by_id(1)
Run Code Online (Sandbox Code Playgroud)
接下来我该怎么办?
谢谢
pdo*_*obb 11
如果要切换布尔值:
u.<attribute>.toggle! # Toggles the boolean and saves without validations
u.<attribute>.toggle # Toggles the boolean and does not save
Run Code Online (Sandbox Code Playgroud)
如果要设置布尔值:
u.<attribute> = [true|false]
Run Code Online (Sandbox Code Playgroud)
如果要立即更新布尔值:
u.update_column(:<attribute>, [true|false]) # Doesn't update timestamps or call callbacks
u.update_attribute(:<attribute>, [true|false]) # Updates timestamps and triggers any callbacks
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6650 次 |
| 最近记录: |