Displaying 1 result from an estimated 1 matches for "test_polymorph".
2006 Feb 15
2
Polymorphic joins work one way, but not the other
...e
belongs_to :attachable, :polymorphic => true
#events table has attachable_type and attachable_id fields
end
class Task < ActiveRecord::Base
has_many :events, :as => :attachable
#tasks tables is nothing special
end
and now a unit test:
#there''s some fixtures above
def test_polymorphics
assert tasks(:simple_task).events << events(:simple_event_1)
assert tasks(:simple_task).events << events(:simple_event_2)
assert events(:simple_event_1).save!
assert tasks(:simple_task).save!
assert_equal 2, tasks(:simple_task).events.size
assert_equal "s...