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 -- Posted via http://www.ruby-forum.com/.
Managed to get it working by changing the fixture to: resource: <%= Fixtures.identify(:row_house) %> resource_type: BuildingType Still don''t like it cause that''s not what RoR is about. Any help would be still highly appreciated :) -- Posted via http://www.ruby-forum.com/.
Have you tried has_many_polymorphs (2.13) http://m.onkey.org/2007/8/14/excuse-me-wtf-is-polymorphs ________________________________ From: Heinz Strunk <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sent: Sunday, September 6, 2009 4:47:51 AM Subject: [Rails] Re: Polymorphic many-to-many relationship? Managed to get it working by changing the fixture to: resource: <%= Fixtures.identify(:row_house) %> resource_type: BuildingType Still don''t like it cause that''s not what RoR is about. Any help would be still highly appreciated :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Does anyone got it working for Rails 3 On Sunday, 6 September 2009 18:58:19 UTC+5:30, Mark Studebaker wrote:> > Have you tried has_many_polymorphs (2.13) > > http://m.onkey.org/2007/8/14/excuse-me-wtf-is-polymorphs > > > ------------------------------ > *From:* Heinz Strunk <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > *To:* rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > *Sent:* Sunday, September 6, 2009 4:47:51 AM > *Subject:* [Rails] Re: Polymorphic many-to-many relationship? > > > Managed to get it working by changing the fixture to: > resource: <%= Fixtures.identify(:row_house) %> > resource_type: BuildingType > > Still don''t like it cause that''s not what RoR is about. Any help would > be still highly appreciated :) > -- > Posted via http://www.ruby-forum.com/. > > > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/8IYKjZGSztoJ. For more options, visit https://groups.google.com/groups/opt_out.