Skip to content

Polymorphic Associations #18

@Matt-Yorkley

Description

@Matt-Yorkley

Hey, I'm having trouble with good_migrations in a migration where one of the classes has a polymorphic association. Just wondering if anyone has hit this issue before, or has any tips?

Here's a rough example of what it looks like:

class MigrateWidgets < ActiveRecord::Migration[5.2]
  class Widget < ActiveRecord::Base
    belongs_to :poly, polymorphic: true
  end
  class Foo < ActiveRecord::Base; end
  class Bar < ActiveRecord::Base; end

  def up
    # Example 1; GoodMigrations::LoadError (attempting to load app/models/foo.rb)
    Widget.where(poly_type: 'Foo').includes(:poly).find_each do |widget|
      # ...
    end

    # Example 2; GoodMigrations::LoadError (attempting to load app/models/bar.rb)
    Widget.where(poly_type: 'Bar').last.poly
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions