Greg Hauptmann
2008-Dec-22 03:39 UTC
is there an activerecord method like "FIND EXISTING OR CREATE NEW IF NONE FOUND"?
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
snacktime
2008-Dec-22 03:51 UTC
Re: is there an activerecord method like "FIND EXISTING OR CREATE NEW IF NONE FOUND"?
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 < greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2008-Dec-22 04:19 UTC
Re: is there an activerecord method like "FIND EXISTING OR CREATE NEW IF NONE FOUND"?
arr thanks - I thought I''d seen them somewhere - I''d been looking through the method names (c.f. content of the doc) On Mon, Dec 22, 2008 at 1:51 PM, snacktime <snacktime-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 < > greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> 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 >> >> >> >> > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Seemingly Similar Threads
- Why does ActiveRecord allow perception of success when updating an ID, however it doesn't really work(i.e. no change in database)?
- x-post : find_or_initialize_by ActiveRecord bug? Ignores :conditions
- ActiveRecord 'find_or_initialize_by' dynamic finder bug? Ignoring conditions.
- Delaying table attribute load using ActiveRecord
- Newbie: using find like a sql join query