figured out the answer to this problem. I needed to use :joins to
include associated models in scopes.
On Oct 11, 10:05 pm, slava
<mikerin.sl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hello,
> Have a question related scope definition. I need to define a scope
> based on related model attribute values like this.
>
> class Product < ActiveRecord::Base
> belongs_to :currency
>
> scope :with_currency, lambda { |currency|
> unless currency.to_s.upcase == ''ALL''
>
> # here I need to define a scope that would test for currency.char_code
> to match a passed value
> # something like.. This is where I need help
> where("currency.char_code = ?", currency.to_s.upcase)
> end
> }
>
> end
>
> class Currency < ActiveRecord::Base
> attr_accessor : char_code
> end
>
> class LineItem < ActiveRecord::Base
> belongs_to :product
>
> scope :with_currency, lambda { |currency|
> unless currency.to_s.upcase == ''ALL''
>
> # here is another scope where I need help..
> where("product.currency.char_code = ?",
currency.to_s.upcase)
> end
> }
>
> end
>
> Thanks for suggestions. Still learning the scoping magic.
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.