Hack hack hack...

An open journal-- some of it written for you, but most of it is for me.

Polymorphic Brain Hurt

Polymorphic association from parent to child

So this succinctly summed up my issue.

Deprecated conditions in rails 4

Deprecation warning when using has_many :through :uniq in Rails 4

Then once I did get it working with:

Conditions Refactor
1
2
3
4
5
6
7
8
9
10
11
12
13
# lesson model
  has_many :readmes, :through => :lesson_contents, :source => :readme,
    :conditions => "lesson_contents.content_type = 'Readme'"

  has_many :labs, :through => :lesson_contents, :source => :lab,
    :conditions => "lesson_contents.content_type = 'Lab'"

# stabby lambda
  has_many :readmes, -> { where("content_type = 'Readme'") },
    :through => :lesson_contents, :source => :readme

  has_many :labs, -> { where("content_type = 'Lab'") }, :through =>
    :lesson_contents, :source => :lab

Hat Tip

Polymorphic Migration

Creating a [polymorphic migration](http://stackoverflow.com/a/5534614/1496757)
1
2
3
4
5
6
7
class AddImageableToProducts < ActiveRecord::Migration
  def up
    change_table :products do |t|
      t.references :imageable, :polymorphic => true
    end
  end
end

Comments