diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index 2871d31c7..6d14a83a0 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -18,6 +18,7 @@ def content_param_list # Relations original_ownerships_attributes: [:id, :original_owner_id, :_destroy], current_ownerships_attributes: [:id, :current_owner_id, :_destroy], + past_ownerships_attributes: [:id, :past_owner_id, :_destroy], maker_relationships_attributes: [:id, :maker_id, :_destroy], ] end diff --git a/app/models/content_groupers/past_ownership.rb b/app/models/content_groupers/past_ownership.rb new file mode 100644 index 000000000..d8a1ea6b6 --- /dev/null +++ b/app/models/content_groupers/past_ownership.rb @@ -0,0 +1,8 @@ +# Defines a relation from an Item to a Character that previously owned it +# and an inverse relationship from an Item to all Characters it has been owned by +class PastOwnership < ActiveRecord::Base + belongs_to :user + + belongs_to :item + belongs_to :past_owner, class_name: 'Character' +end diff --git a/app/models/item.rb b/app/models/item.rb index 280a2a513..9e69f44fc 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -18,6 +18,7 @@ class Item < ActiveRecord::Base # Characters relates :original_owners, with: :original_ownerships + relates :past_owners, with: :past_ownerships relates :current_owners, with: :current_ownerships relates :makers, with: :maker_relationships @@ -43,7 +44,7 @@ def self.attribute_categories }, history: { icon: 'book', - attributes: %w(original_owners current_owners makers year_made) + attributes: %w(original_owners past_owners current_owners makers year_made) }, abilities: { icon: 'flash_on', diff --git a/db/migrate/20161001232324_create_past_ownership.rb b/db/migrate/20161001232324_create_past_ownership.rb new file mode 100644 index 000000000..99581da7f --- /dev/null +++ b/db/migrate/20161001232324_create_past_ownership.rb @@ -0,0 +1,9 @@ +class CreatePastOwnership < ActiveRecord::Migration + def change + create_table :past_ownerships do |t| + t.integer :user_id + t.integer :item_id + t.integer :past_owner_id + end + end +end diff --git a/db/schema.rb b/db/schema.rb index a7dc25434..023e38ab4 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160922204317) do +ActiveRecord::Schema.define(version: 20161001232324) do create_table "archenemyships", force: :cascade do |t| t.integer "user_id" @@ -206,6 +206,12 @@ t.datetime "updated_at", null: false end + create_table "past_ownerships", force: :cascade do |t| + t.integer "user_id" + t.integer "item_id" + t.integer "past_owner_id" + end + create_table "sessions", force: :cascade do |t| t.string "username", null: false t.string "password", null: false