I’m testing Rails 3 beta 4 on Ruby 1.9.2-head, and when I start a
console and do:
Game.first.to_sql
I get this error:
ArgumentError: wrong number of arguments (0 for 1)
I know it can find the Game record, because when I type:
Game.first
it returns:
=> #<Game id: 1, name: "Galaga", created_at: "2010-06-19 11:02:37",
updated_at: "2010-06-19 11:02:37">
What am I missing? I just want to make the to_sql work in a very simple
case.
.
When you run
Game.firstyou are returning aGameobject, not aActiveRecord::Relationobject as you are expecting.To do what you’re trying to do, you’ll need to do:
This lets you run it without
to_sqland return the object as you expected it, although it will be in an array, which then you can run.firston it like you wanted anyways.When you dig into the source, when you run
.firston an ActiveRecord::Relation it runs the following (which is the same as I showed you):