On May 7, 5:58 pm, erik <e...@carwoo.com> wrote:
> I'm new to named_scope so bear with me if this is dumb.
>
> I have created two named scopes both using lambda to pass in
> arguments.  One passes in a single argument and works great the other
> passes in two arguments and doesn't work and gives me this error:
>
I'm going to make a wild guess that this is because you're assuming
that OrderTrack.one(...) is a single object rather than an array
(possibly containing only one row)

Fred

> undefined method `last_reference' for #<Class:0x4464cb4>
>
> vendor/rails/activerecord/lib/active_record/base.rb:1833:in
> `method_missing_without_paginate'
> /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/mislav-
> will_paginate-2.3.8/lib/will_paginate/finder.rb:170:in
> `method_missing'
> vendor/rails/activerecord/lib/active_record/named_scope.rb:171:in
> `send'
> vendor/rails/activerecord/lib/active_record/named_scope.rb:171:in
> `method_missing'
> vendor/rails/activerecord/lib/active_record/base.rb:2003:in
> `with_scope'
> (__DELEGATION__):2:in `__send__'
> (__DELEGATION__):2:in `with_scope'
> app/controllers/orders_controller.rb:23:in `show'
>
> The two named_scopes:
> class OrderTrack < ActiveRecord::Base
>     named_scope :one, lambda {|id,account_id| {:conditions => ["id = ?
> and account_id = ?",id,account_id]}}
>     named_scope :all, lambda {|account_id| {:conditions =>
> ["account_id = ?",account_id]}}
> end
>
> I believe I need to use lambda to pass in arguments.  The
> named_scope :all works great and ends up doing an sql query like:
> SELECT * FROM `order_tracks` WHERE (account_id = 344)
>
> But the single one that I want to end up doing something like:
> SELECT * FROM `order_tracks` WHERE (id = 3 and account_id = 344)
> doesn't want to work.
>
> This is soft of a contrived example, but I'm just trying to see if I
> understand this stuff.
> Thanks.
> Erik
--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to