makandra / active_type

Make any Ruby object quack like ActiveRecord
MIT License
1.09k stars 74 forks source link

Fix change_association with polymorphic association #117

Closed lucthev closed 4 years ago

lucthev commented 4 years ago

When using change_assocation with a polymorphic association, active type is overwriting the association's foreign_key, causing "unknown column" errors.

Fix this by skipping the foreign key override when using a polymorphic association (as: ...).

triskweline commented 4 years ago

Thanks for the PR @lucthev .

The change looks good to me @kratob . I was hesistant over the change unless options[:foreign_key] || options[:as], but I guess that the :as option implies :foreign_key, since we're using the foreign key from the polymorphic interface.

kratob commented 4 years ago

I think this looks good. I've released the change as version 1.3.1.