Skip to content

Instantly share code, notes, and snippets.

@nicbet
Created November 12, 2018 15:17
Show Gist options
  • Save nicbet/5156f661b778bd6eb14ad15e389f9a0f to your computer and use it in GitHub Desktop.
Save nicbet/5156f661b778bd6eb14ad15e389f9a0f to your computer and use it in GitHub Desktop.
Rails polymorphic associations
class Person < ActiveRecord::Base
  has_one :address, :as => :addressable
end

class Company < ActiveRecord::Base
  has_one :address, :as => :addressable
end

class Address < ActiveRecord::Base
  belongs_to :addressable, :polymorphic => true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment