Created
December 1, 2013 15:57
-
-
Save anonymous/7735622 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Project.first.items # fails, undefined method 'items' | |
| Project.first.project_items # no results ever | |
| Project.first.features # could not find the association :item in model Project | |
| Project.first.milestones # could not find the association :item in model Project | |
| ProjectItem.first.feature # undefined method 'feature' | |
| ProjectItem.first.milestone # undefined method 'milestone' | |
| Feature.first.project_item.project.name # works, but expected Feature.first.item.project.name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Project < ActiveRecord::Base | |
| has_many :project_items, as: :item, class_name: "ProjectItem", dependent: :destroy | |
| has_many :features, through: :item, class_name: "ProjectItem", dependent: :destroy | |
| has_many :milestones, through: :item, class_name: "ProjectItem", dependent: :destroy | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ProjectItem < ActiveRecord::Base | |
| belongs_to :item, touch: true, polymorphic: true | |
| belongs_to :project, touch: true | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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