Skip to content

Instantly share code, notes, and snippets.

@universal
Forked from anonymous/feature_and_milestone.rb
Last active December 29, 2015 22:39
Show Gist options
  • Select an option

  • Save universal/7738070 to your computer and use it in GitHub Desktop.

Select an option

Save universal/7738070 to your computer and use it in GitHub Desktop.
class Feature < ActiveRecord::Base
has_one :project_item, as: :item, class_name: "ProjectItem"
end
class Milestone < ActiveRecord::Base
has_one :project_item, as: :item, class_name: "ProjectItem"
end
class Project < ActiveRecord::Base
has_many :project_items
has_many :features, through: :project_items, source_type: "Feature", source: :item
has_many :milestones, through: :project_items, source_type: "Milestone", source: :item
end
class ProjectItem < ActiveRecord::Base
belongs_to :item, touch: true, polymorphic: true
belongs_to :project, touch: true
end
create_table "project_items", force: true do |t|
t.integer "project_id"
t.integer "item_id"
t.string "item_type"
t.integer "position"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "projects", force: true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "features", force: true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "milestones", force: true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment