I need to do a few custom SQL join''s so was mucking around in the console AR stuff works fine when trying to access the instance.id @tile = Tile.find(:first, :conditions => ["id = ? ", 10 ])>> @tile.id=> 10 but doing a custom SQL query I get this when trying to look at instance.id @tile = Tile.find_by_sql("select id, blog_name FROM tiles WHERE tiles.id 10")>> @tile.id(irb):85: warning: Object#id will be deprecated; use Object#object_id => 29652588 I have seen a few posts which say to do stuff like to access the object id instead of the ruby id class << ActiveRecord alias "id__", "id" end but this seems uncool to me can anyone (DHH) explain whats going on here??? cheers heaps dion -- www.blogsaic.com search, post, blog --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> @tile = Tile.find_by_sql ("select id, blog_name FROM tiles WHERE tiles.id > 10") > >> @tile.id > (irb):85: warning: Object#id will be deprecated; use Object#object_id > => 29652588I''m guessing that @tile is an array. You probably want this instead: @tile = Tile.find_by_sql ("select id, blog_name FROM tiles WHERE tiles.id > 10").first If you need help, just do something like this: @tile.class That''ll tell you what you''re dealing with. -- Rick Olson http://weblog.techno-weenie.net http://mephistoblog.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 -~----------~----~----~----~------~----~------~--~---
find_by_sql returns an array, as it works like find(:all) if you were to do @tile.class you would get Array Chris On 9/11/06, Dion Hewson <dionhewson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I need to do a few custom SQL join''s > > so was mucking around in the console > > AR stuff works fine when trying to access the instance.id > > @tile = Tile.find(:first, :conditions => ["id = ? ", 10 ]) > >> @tile.id > => 10 > > but doing a custom SQL query I get this when trying to look at instance.id > > @tile = Tile.find_by_sql ("select id, blog_name FROM tiles WHERE tiles.id > 10") > >> @tile.id > (irb):85: warning: Object#id will be deprecated; use Object#object_id > => 29652588 > > I have seen a few posts which say to do stuff like to access the object id > instead of the ruby id > > class << ActiveRecord > alias "id__", "id" > > end > > but this seems uncool to me > > can anyone (DHH) explain whats going on here??? > > cheers heaps > > dion > > -- > > www.blogsaic.com > search, post, blog > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
sorry about that I was being a dick I was using some code from my pagination stuff and fogot to loop through the array like I normally do <% for row in @tiles %> cheers On 9/12/06, Chris Hall <christopher.k.hall-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > find_by_sql returns an array, as it works like find(:all) > > if you were to do @tile.class you would get Array > > Chris > > On 9/11/06, Dion Hewson <dionhewson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I need to do a few custom SQL join''s > > > > so was mucking around in the console > > > > AR stuff works fine when trying to access the instance.id > > > > @tile = Tile.find(:first, :conditions => ["id = ? ", 10 ]) > > >> @tile.id > > => 10 > > > > but doing a custom SQL query I get this when trying to look at > instance.id > > > > @tile = Tile.find_by_sql ("select id, blog_name FROM tiles WHERE > tiles.id > > 10") > > >> @tile.id > > (irb):85: warning: Object#id will be deprecated; use Object#object_id > > => 29652588 > > > > I have seen a few posts which say to do stuff like to access the object > id > > instead of the ruby id > > > > class << ActiveRecord > > alias "id__", "id" > > > > end > > > > but this seems uncool to me > > > > can anyone (DHH) explain whats going on here??? > > > > cheers heaps > > > > dion > > > > -- > > > > www.blogsaic.com > > search, post, blog > > > > > > > > >-- www.blogsaic.com search, post, blog --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---