This project is archived and is in readonly mode.
Add AR::Base#just_created? to differentiate records
-
RSL
- Title changed from Add AR::Base#just_created? to differenciate records to Add AR::Base#just_created? to differentiate records
-
RSL
To clarify the benefit of this over writing out the find_or_initialize song and dance mentioned above there are two cases where having a method to check would be better.
- Where the find_or_create call is internal to a another wrapper method.
- Where you need to operate on a saved record [most likely needing the id attribute].
-
Jaime Bellmyer
- It includes/passes tests, and works as advertised, and seems to stick with rails conventions. At first I didn't see the usefulness, but I have to admit after trying it out, I can see how it would be helpful. I like it!
-
Jaime Bellmyer
Sorry, my post above started with "+1", but formatting seems to have mangled it. +1
-
Pratik
- Assigned user set to Pratik
- State changed from new to wontfix
just_created? should return false for new records. Also, let's wait till someone else wants the same feature, then I'll push it.
Thanks.
-
RSL
Updated patch per Pratik
-
Richie Vos
I'll +1 this as well. I am doing my own find_or_create'ish code in an update (trying to properly handle proper PUT semantics), and need exactly this. I thought rails had new_record_before_save?, but that appears to be part of the association internals.
I like the method name as well.
I'm not sure what the behavior of multiple saves should be:
item = Item.create item.save # should just_created? still be true hereI personally could see an argument for either, but I'd think it should be false after the 2nd save. Especially if the object changed between the saves.
