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
Rick_Olson
(Rick Olson)
September 12, 2006, 2:04am
2
@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'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.
Chris_Hall
(Chris Hall)
September 12, 2006, 2:08am
3
find_by_sql returns an array, as it works like find(:all)
if you were to do @tile.class you would get Array
Chris
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