开发者

How to check a model object is persisted to DB or a new object?

开发者 https://www.devze.com 2023-01-22 18:06 出处:网络
category = Category.new This isn\'t persi开发者_运维百科sted to DB yet, so how to distinguish form an object that is saved in the database?c.persisted?# => true if persisted
category = Category.new

This isn't persi开发者_运维百科sted to DB yet, so how to distinguish form an object that is saved in the database?


c.persisted?  # => true if persisted
c.new_record? # => true if not persisted

:)


c.new_record? # true if new, false if saved
0

精彩评论

暂无评论...
验证码 换一张
取 消