diff --git a/app/controllers/characters_controller.rb b/app/controllers/characters_controller.rb index e0a8f3d6..7eba14ff 100644 --- a/app/controllers/characters_controller.rb +++ b/app/controllers/characters_controller.rb @@ -11,8 +11,8 @@ class CharactersController < ContentController [ :universe_id, :user_id, :name, :age, :role, :gender, :age, :archetype, :height, :weight, :haircolor, - :facialhair, :eyecolor, :race, :skintone, :bodytype, :identmarks, :hairstyle, - :religion, :politics, :prejudices, :occupation, :pets, :aliases, + :facialhair, :eyecolor, :skintone, :bodytype, :identmarks, :hairstyle, + :religion, :politics, :prejudices, :occupation, :pets, :aliases, :race, :mannerisms, :birthday, :education, :background, :motivations, :flaws, :talents, :hobbies, :personality_type, :fave_color, :fave_food, :fave_possession, :fave_weapon, :fave_animal, diff --git a/app/models/content_groupers/raceship.rb b/app/models/content_groupers/raceship.rb new file mode 100644 index 00000000..744447ef --- /dev/null +++ b/app/models/content_groupers/raceship.rb @@ -0,0 +1,6 @@ +class Raceship < ActiveRecord::Base + belongs_to :user + + belongs_to :character + belongs_to :race +end diff --git a/app/models/content_types/character.rb b/app/models/content_types/character.rb index 733abc3c..2dd0c0b1 100644 --- a/app/models/content_types/character.rb +++ b/app/models/content_types/character.rb @@ -33,6 +33,9 @@ class Character < ActiveRecord::Base # Items relates :favorite_items, with: :ownerships, where: { favorite: true } + # Races + relates :races, with: :raceships + scope :is_public, -> { eager_load(:universe).where('characters.privacy = ? OR universes.privacy = ?', 'public', 'public') } def description @@ -55,7 +58,7 @@ class Character < ActiveRecord::Base }, looks: { icon: 'face', - attributes: %w(weight height haircolor hairstyle facialhair eyecolor race skintone bodytype identmarks) + attributes: %w(weight height haircolor hairstyle facialhair eyecolor skintone bodytype identmarks races) }, nature: { icon: 'fingerprint', diff --git a/db/migrate/20161021220223_create_raceships.rb b/db/migrate/20161021220223_create_raceships.rb new file mode 100644 index 00000000..dd0785b7 --- /dev/null +++ b/db/migrate/20161021220223_create_raceships.rb @@ -0,0 +1,9 @@ +class CreateRaceships < ActiveRecord::Migration + def change + create_table :raceships do |t| + t.integer :user_id + t.integer :character_id + t.integer :race_id + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 8768cb17..08a4a807 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: 20161021211814) do +ActiveRecord::Schema.define(version: 20161021220223) do create_table "archenemyships", force: :cascade do |t| t.integer "user_id" @@ -351,6 +351,12 @@ ActiveRecord::Schema.define(version: 20161021211814) do t.datetime "updated_at", null: false end + create_table "raceships", force: :cascade do |t| + t.integer "user_id" + t.integer "character_id" + t.integer "race_id" + end + create_table "religions", force: :cascade do |t| t.string "name" t.string "description" diff --git a/lib/tasks/data_migrations.rake b/lib/tasks/data_migrations.rake index 4f4af37b..43f276fd 100644 --- a/lib/tasks/data_migrations.rake +++ b/lib/tasks/data_migrations.rake @@ -2,19 +2,16 @@ namespace :data_migrations do desc "Create a race for each user, for each of their characters with a `race` value" task create_races_from_character_races: :environment do - users.each do |user| - puts "Migrating user #{user.email.split('@').first}..."" + User.all.each do |user| + puts "Migrating user #{user.email.split('@').first}..." + user.characters.where.not(race: "").each do |character| + race = character.race - end + puts "\tCreating race #{race}" - users = User.confirmed - puts "Going to update #{users.count} users" - - ActiveRecord::Base.transaction do - users.each do |user| - user.mark_newsletter_received! - print "." + new_race = user.races.where(name: race).first_or_create + character.races << new_race end end