Forum: Ruby on Rails is there an activerecord method like "FIND EXISTING OR CREATE NEW IF NONE FOUND"?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D5df9fcd7ef4c3c937435d7d6adeab2a?d=identicon&s=25 Greg Hauptmann (Guest)
on 2008-12-22 04:39
(Received via mailing list)
Just wondering if rails has a method to look for an existing record and
return it, but if it's not existing then create a new record.   (i.e.
"FIND
EXISTING OR CREATE NEW IF NONE FOUND"?)

Then when finished updating one could use the existing "save" method
which
caters for either a new or updated record already

Thanks
F48118fe74b0c7f6fd82a0ee422fa34e?d=identicon&s=25 snacktime (Guest)
on 2008-12-22 04:52
(Received via mailing list)
Yes, look at dynamic attribute based finders in the activercord docs.
http://api.rubyonrails.org/classes/ActiveRecord/Base.html.

Chris

On Sun, Dec 21, 2008 at 7:39 PM, Greg Hauptmann <
D5df9fcd7ef4c3c937435d7d6adeab2a?d=identicon&s=25 Greg Hauptmann (Guest)
on 2008-12-22 05:20
(Received via mailing list)
arr thanks - I thought I'd seen them somewhere - I'd been looking
through
the method names (c.f. content of the doc)
This topic is locked and can not be replied to.