evan / has_many_polymorphs

An ActiveRecord plugin for self-referential and double-sided polymorphic associations.
http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/
Academic Free License v3.0
201 stars 57 forks source link

association.include?(associated) fails oddly #5

Open jamesarosen opened 15 years ago

jamesarosen commented 15 years ago

I have a owner model:

class Person < ActiveRecord::Base
  has_many_polymorphs :things, :from => [ :books, :cds, :dvds ], :through => :person_things
end

a relationship model:

class PersonThing < ActiveRecord::Base
  belongs_to :person
  belongs_to :thing, :polymorphic => true
end 

and several owned models:

class Book < ActiveRecord::Base
end
...

If I create a relationship:

person = Person.create!(:name => 'Barney')
book = Book.create!('Dinosaurs for Dummies')
person.things << book

then include? fails even when select doesn't:

person.things.include? book
# => false
person.things.select { |t| t == book }.any?
# => true

I'm guessing include? is redefined on this enumeration, but it's not redefined correctly.

ghost commented 15 years ago

best bet is to make a failing test and fix it yourself; this project is in patch-accepting-mode only :-/