如果我的数据库设置为false,更新数据库中的布尔值的最佳实践是什么?
我可以在控制台上执行此操作:
>> u = User.find_by_id(1)
接下来我该怎么办?
谢谢
如果要切换布尔值:
u.toggle!(:<attribute>) # Toggles the boolean and saves without validations
u.toggle(:<attribute>) # Toggles the boolean and does not save
如果要设置布尔值:
u.<attribute> = [true|false]
如果要立即更新布尔值:
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句