Add leaders relation between location and characters

This commit is contained in:
Andrew Brown 2016-09-03 17:21:10 -05:00
parent 51fecdcaea
commit f3d7dbca2b
5 changed files with 28 additions and 2 deletions

View File

@ -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]

View File

@ -0,0 +1,6 @@
class LocationLeadership < ActiveRecord::Base
belongs_to :user
belongs_to :location
belongs_to :leader, class_name: 'Character'
end

View File

@ -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',

View File

@ -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

View File

@ -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"