From f3d7dbca2b1cd9065b3e2cbb0812ef9eea792d7b Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sat, 3 Sep 2016 17:21:10 -0500 Subject: [PATCH] Add leaders relation between location and characters --- app/controllers/locations_controller.rb | 2 ++ app/models/content_groupers/location_leadership.rb | 6 ++++++ app/models/location.rb | 5 ++++- db/migrate/20160903221819_create_location_leaderships.rb | 9 +++++++++ db/schema.rb | 8 +++++++- 5 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 app/models/content_groupers/location_leadership.rb create mode 100644 db/migrate/20160903221819_create_location_leaderships.rb diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index ba6e1a34..a1481ec5 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -16,6 +16,8 @@ class LocationsController < ContentController :notes, :private_notes, # Relations + #todo might be able to inject/reflect these from :relates concern implementation + location_leaderships_attributes: [:id, :leader_id, :_destroy], capital_cities_relationships_attributes: [:id, :capital_city_id, :_destroy], largest_cities_relationships_attributes: [:id, :largest_city_id, :_destroy], notable_cities_relationships_attributes: [:id, :notable_city_id, :_destroy] diff --git a/app/models/content_groupers/location_leadership.rb b/app/models/content_groupers/location_leadership.rb new file mode 100644 index 00000000..f426a2a4 --- /dev/null +++ b/app/models/content_groupers/location_leadership.rb @@ -0,0 +1,6 @@ +class LocationLeadership < ActiveRecord::Base + belongs_to :user + + belongs_to :location + belongs_to :leader, class_name: 'Character' +end diff --git a/app/models/location.rb b/app/models/location.rb index 13670b0c..0e51379f 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -17,6 +17,9 @@ class Location < ActiveRecord::Base include HasContentGroupers + # Characters + relates :leaders, with: :location_leaderships + # Locations relates :capital_cities, with: :capital_cities_relationships relates :largest_cities, with: :largest_cities_relationships @@ -39,7 +42,7 @@ class Location < ActiveRecord::Base # TODO: map culture: { icon: 'face', - attributes: %w(population language currency motto) + attributes: %w(leaders population language currency motto) }, cities: { icon: 'face', diff --git a/db/migrate/20160903221819_create_location_leaderships.rb b/db/migrate/20160903221819_create_location_leaderships.rb new file mode 100644 index 00000000..914eeef5 --- /dev/null +++ b/db/migrate/20160903221819_create_location_leaderships.rb @@ -0,0 +1,9 @@ +class CreateLocationLeaderships < ActiveRecord::Migration + def change + create_table :location_leaderships do |t| + t.integer :user_id + t.integer :location_id + t.integer :leader_id + end + end +end diff --git a/db/schema.rb b/db/schema.rb index b19457db..b0a78a52 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: 20160903221349) do +ActiveRecord::Schema.define(version: 20160903221819) do create_table "archenemyships", force: :cascade do |t| t.integer "user_id" @@ -120,6 +120,12 @@ ActiveRecord::Schema.define(version: 20160903221349) do t.integer "largest_city_id" end + create_table "location_leaderships", force: :cascade do |t| + t.integer "user_id" + t.integer "location_id" + t.integer "leader_id" + end + create_table "locations", force: :cascade do |t| t.string "name", null: false t.string "type_of"