When I use Model.find(:last) I get an error saying that it can’t find an
ID=last. How come?
Pål Bergström wrote:
When I use Model.find(:last) I get an error saying that it can’t find an
ID=last. How come?
Do you have a column “id” or something to index with?
Maybe, try find_by_id or find_by_column-name(:last)
Justin To wrote:
Pål Bergström wrote:
When I use Model.find(:last) I get an error saying that it can’t find an
ID=last. How come?Do you have a column “id” or something to index with?
Maybe, try find_by_id or find_by_column-name(:last)
Not sure what you mean. I have and id, yes. I’m just trying to find that
last record with :last, the opposite to :first.
On Thu, 2008-07-24 at 22:25 +0200, Pål Bergström wrote:
When I use Model.find(:last) I get an error saying that it can’t find an
ID=last. How come?
not an implemented option
http://rails.rubyonrails.org/classes/ActiveResource/Base.html#M000933
Craig
Pål Bergström wrote:
When I use Model.find(:last) I get an error saying that it can’t find an
ID=last. How come?
There’s no option :last. Instead, find(:first) but specify an order to
reverse them. For example:
Model.find(:first, :order => ‘created_at desc’)
This will fetch the most recently created item.
Jeremy Weiskotten wrote:
Pål Bergström wrote:
When I use Model.find(:last) I get an error saying that it can’t find an
ID=last. How come?There’s no option :last. Instead, find(:first) but specify an order to
reverse them. For example:Model.find(:first, :order => ‘created_at desc’)
This will fetch the most recently created item.
Hmm. From the api:
find last
Person.find(:last) # returns the last object fetched by SELECT * FROM
people
Person.find(:last, :conditions => [ “user_name = ?”, user_name])
Person.find(:last, :order => “created_on DESC”, :offset => 5)
Craig W. wrote:
On Thu, 2008-07-24 at 22:25 +0200, Pål Bergström wrote:
When I use Model.find(:last) I get an error saying that it can’t find an
ID=last. How come?
not an implemented option
http://rails.rubyonrails.org/classes/ActiveResource/Base.html#M000933
Craig
I understand. Why is it in there?
On Thu, 2008-07-24 at 23:40 +0200, Pål Bergström wrote:
I understand. Why is it in there?
with optional arguments it works, without optional arguments, it
fails…
Personnel.find :last
ActiveRecord::StatementInvalid: PGError: ERROR: invalid input syntax
for integer: "— :last
"
: SELECT * FROM personnels WHERE (personnels.“id” = '— :last
')
at least it fails with postgres…perhaps some of the SQL adaptors can
make sense of the query
Craig
Jeremy Weiskotten wrote:
Interesting, that was added in March. What version of Rails are you
using? I’m guessing you need 2.1.
I see. I run 2.0.2. That explains it.
Interesting, that was added in March. What version of Rails are you
using? I’m guessing you need 2.1.
at least it fails with postgres…perhaps some of the SQL adaptors can
make sense of the queryCraig
Working for me with postgres 8.3.1 with or without options.
Even if you’re using a version of Rails that doesn’t have the
find(:last) option, you can essentially pull of the same thing with:
find(:first, :order => ‘id desc’)
I think that may even be what the Rails method does.
– Josh
Jeremy Weiskotten wrote:
at least it fails with postgres…perhaps some of the SQL adaptors can
make sense of the queryCraig
Working for me with postgres 8.3.1 with or without options.
Joshua A. wrote:
Even if you’re using a version of Rails that doesn’t have the
find(:last) option, you can essentially pull of the same thing with:find(:first, :order => ‘id desc’)
I think that may even be what the Rails method does.
– Josh
Yes, I know. I normally use that. Then I saw :last in the api.
On Thu, Jul 24, 2008 at 3:25 PM,
Pål Bergström[email protected] wrote:
When I use Model.find(:last) I get an error saying that it can’t find an
ID=last. How come?
There is no Model.find(:first).
You need to do Model.find(:first, :order => ‘?? DESC’)
With me Model.first works… Model.last works as well… no need for
Model.find…