Good morning,
I need to implement a many-to-many polymorphic relationship. Any of my books, Google and the search couldn't help me.
habtm doesn't work cause it doesn't support :polymorphic so this is my approach so far:
ActivityType model: has_many :activity_type_scopes, :as => :resource
BuildingType model: has_many :activity_type_scopes, :as => :activity_type_id BlockType model: has_many :activity_type_scopes, :as => :activity_type_id
ActivityTypeScope model: belongs_to :activity_type belongs_to :resource, :polymorphic => true
ActivityTypeScope migration: create_table :activity_type_scopes, :id => false do |t| t.integer :activity_type_id t.integer :resource_id t.string :resource_type t.timestamps end
I don't really like that approach but 2.2.2 doesn't seem to have a decent solution to this. Anyway when I load a the fuxture ActivityTypeScope: one: activity_type: burglary resource: <%= BuildingType.find(Fixtures.identify(:row_house)) %>
It says BuildingType with the ID 1234567 couldn't be found, if I use the ID instead of BuildingType.find(Fixtures.identify(:row_house)) I get no errors but resource_id and resource_type is NULL in the database.
Anyone knows what's wrong with this or - even better - does anyone have a better solution to my polymorphic habtm problem?
Thanks a lot, Heinz