SchemaPlus / schema_associations

ActiveRecord extension that automatically (DRY) creates associations based on the schema
Other
46 stars 8 forks source link

Should handle polymorphic associations #5

Open ronen opened 12 years ago

ronen commented 12 years ago

Recognize a polymorphic association by the convention of columns named 'foo_id' and 'foo_type', when those columns have the appropriate types and table 'foos' exists.

This would build on Issue #4 -- creating associations without foreign key constraints

romdim commented 8 years ago

Hello there! Seems like a great gem overall and I just started using it, the thing is that I already have a lot of polymorphic associations. Is there a chance for this feature to come in life? Thank you for all your effort!

ronen commented 8 years ago

Hello, I'd be happy to accept a PR but unlikely to have time to work on it myself.

Handling the polymorphic belongs_to association should be reasonably straightforward. But a tricky question would be how to automatically generate the reverse has_many associations (since they depend on the contents of the _type column); I have some half-baked ideas but not sure if they'd really work. If there's anyone out there (you?) who wants to try it I'm happy to discuss.

romdim commented 8 years ago

Unfortunately I'm not in a better position myself and additionally not enough experience with ruby to work on it I think.. When I find any time I'd be happy to discuss it with you! Will use the basic way for now.. Cheers!