Programing

ActiveRecord 객체가 New인지 확인

lottogame 2020. 5. 1. 08:00
반응형

ActiveRecord 객체가 New인지 확인


ActiveRecord객체가 새로운 지 또는 이미 지속 되는지 어떻게 확인할 수 있습니까?


#new_record? 그냥 그렇게 :

object.new_record?

ActiveRecord 객체 수명주기 :

1. 새로운 기록

item = Item.new
item.new_record? #=> true

2. 지속

item.save
item.persisted? #=> true

3. 변경

item.name = "other"
item.changed? #=> true

4. 파괴

item.destroy
item.destroyed? #=> true

참고 URL : https://stackoverflow.com/questions/7842920/determine-if-activerecord-object-is-new

반응형