Hi guys, another question: I have a struct, which contains records returned from a query. I then perform a loop which runs another query which adds more records to the struct, but I would like to check whether the record already exists before adding it, is there a way to search a struct, say by id, to check the existance of said record before I add it? Cheers Mick -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Put the records into a Hash instead, using the id as the key. Then if you put in a record with the same id, it just overwrites it. b Mick wrote:> Hi guys, another question: > > I have a struct, which contains records returned from a query. I then > perform a loop which runs another query which adds more records to the > struct, but I would like to check whether the record already exists > before adding it, is there a way to search a struct, say by id, to check > the existance of said record before I add it? > > Cheers > > Mick >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
rein.henrichs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Apr-22 16:56 UTC
Re: Struct search
What is the purpose of using a Struct? ActiveRecord objects already have setter and getter methods. you can just use a normal array and either uniq it or use Array#| (the set union operator) like @collection | @new_records to save a bit. Also note that a Hash is unordered. Regards, Rein --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---