Can anyone help me with this?
I have a habtm relationship. I defined a named_scope on one side of
it. It works fine except when I chain it. For example:
[code]
class Category < ActiveRecord::Base
has_and_belongs_to_many :items
end
class Item < ActiveRecord::Base
has_and_belongs_to_many :categories
named_scope :cat, lambda {|cat| {:include
=> :categories, :conditions => ["categories.id = ?", cat]}}
end
[/code]
Simple. Easy. Normal, right?
But, let''s see I have the following in my join table
"categories_items":
category_id | item_id
------------------------------
1 1
1 2
2 2
2 3
So I try some console stuff (I''m taking out the object return and just
showing the IDs)
> Item.cat(1) # => [1,2]
> Item.cat(2) # => [2,3]
> Item.cat(1).cat(2) # => []
WAIT! Shouldn''t that return [2] ?
Is this a bug? Or am I misunderstanding something?
If I force the "AND" it works:> Item.cat(1) & Item.cat(2) # => [2]
So the chaining of named scopes seems not to be working here.
Help?!?
-Danimal
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---