Skip to content

Commit

Permalink
Add deity and character siblings to deities
Browse files Browse the repository at this point in the history
  • Loading branch information
drusepth committed Feb 2, 2018
1 parent d41b77d commit 7a58736
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/controllers/deities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ def content_param_list
deity_character_parents_attributes: [:id, :character_parent_id, :_destroy],
deity_character_partners_attributes: [:id, :character_partner_id, :_destroy],
deity_character_children_attributes: [:id, :character_child_id, :_destroy],
deity_character_siblings_attributes: [:id, :character_sibling_id, :_destroy],
deity_deity_parents_attributes: [:id, :deity_parent_id, :_destroy],
deity_deity_partners_attributes: [:id, :deity_partner_id, :_destroy],
deity_deity_children_attributes: [:id, :deity_child_id, :_destroy],
deity_deity_siblings_attributes: [:id, :deity_sibling_id, :_destroy],
deity_creatures_attributes: [:id, :creature_id, :_destroy],
deity_floras_attributes: [:id, :flora_id, :_destroy],
deity_religions_attributes: [:id, :religion_id, :_destroy],
Expand Down
7 changes: 7 additions & 0 deletions app/models/content_groupers/deity_character_sibling.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class DeityCharacterSibling < ActiveRecord::Base
include HasContentLinking

belongs_to :deity
belongs_to :character_sibling, class_name: Character.name
belongs_to :user
end
23 changes: 23 additions & 0 deletions app/models/content_groupers/deity_deity_sibling.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class DeityDeitySibling < ActiveRecord::Base
include HasContentLinking

belongs_to :deity
belongs_to :deity_sibling, class_name: Deity.name
belongs_to :user

after_create do
self.reciprocate(
relation: :deity_deity_siblings,
parent_object_ref: :deity,
added_object_ref: :deity_sibling
)
end

after_destroy do
# This is a two-way relation, so we should also delete the reverse association
this_object = Deity.find_by(id: self.deity_id)
other_object = Deity.find_by(id: self.deity_sibling_id)

other_object.deity_siblings.delete(this_object) unless other_object.nil?
end
end
4 changes: 3 additions & 1 deletion app/models/content_types/deity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ class Deity < ActiveRecord::Base
relates :character_parents, with: :deity_character_parents
relates :character_partners, with: :deity_character_partners
relates :character_children, with: :deity_character_children
relates :character_siblings, with: :deity_character_siblings
relates :deity_parents, with: :deity_deity_parents
relates :deity_partners, with: :deity_deity_partners
relates :deity_children, with: :deity_deity_children
relates :deity_siblings, with: :deity_deity_siblings
relates :creatures, with: :deity_creatures
relates :floras, with: :deity_floras
relates :religions, with: :deity_religions
Expand All @@ -31,7 +33,7 @@ class Deity < ActiveRecord::Base
relates :related_landmarks, with: :deity_related_landmarks

def self.color
'text-lighten-1 grey'
'text-lighten-4 blue'
end

def self.icon
Expand Down
4 changes: 4 additions & 0 deletions config/attributes/deity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@
:label: Partners
- :name: character_children
:label: Children
- :name: character_siblings
:label: Siblings
- :name: deity_parents
:label: Parents
- :name: deity_partners
:label: Partners
- :name: deity_children
:label: Children
- :name: deity_siblings
:label: Siblings
:symbolism:
:label: Symbolism
:icon: thumbs_up_down
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20180202055802_create_deity_character_siblings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateDeityCharacterSiblings < ActiveRecord::Migration
def change
create_table :deity_character_siblings do |t|
t.references :deity, index: true, foreign_key: true
t.integer :character_sibling_id
t.references :user, index: true, foreign_key: true

t.timestamps null: false
end
end
end
11 changes: 11 additions & 0 deletions db/migrate/20180202055822_create_deity_deity_siblings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateDeityDeitySiblings < ActiveRecord::Migration
def change
create_table :deity_deity_siblings do |t|
t.references :deity, index: true, foreign_key: true
t.integer :deity_sibling_id
t.references :user, index: true, foreign_key: true

t.timestamps null: false
end
end
end
24 changes: 23 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20180131064902) do
ActiveRecord::Schema.define(version: 20180202055822) do

create_table "archenemyships", force: :cascade do |t|
t.integer "user_id"
Expand Down Expand Up @@ -545,6 +545,17 @@
add_index "deity_character_partners", ["deity_id"], name: "index_deity_character_partners_on_deity_id"
add_index "deity_character_partners", ["user_id"], name: "index_deity_character_partners_on_user_id"

create_table "deity_character_siblings", force: :cascade do |t|
t.integer "deity_id"
t.integer "character_sibling_id"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "deity_character_siblings", ["deity_id"], name: "index_deity_character_siblings_on_deity_id"
add_index "deity_character_siblings", ["user_id"], name: "index_deity_character_siblings_on_user_id"

create_table "deity_creatures", force: :cascade do |t|
t.integer "user_id"
t.integer "deity_id"
Expand Down Expand Up @@ -590,6 +601,17 @@
add_index "deity_deity_partners", ["deity_id"], name: "index_deity_deity_partners_on_deity_id"
add_index "deity_deity_partners", ["user_id"], name: "index_deity_deity_partners_on_user_id"

create_table "deity_deity_siblings", force: :cascade do |t|
t.integer "deity_id"
t.integer "deity_sibling_id"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "deity_deity_siblings", ["deity_id"], name: "index_deity_deity_siblings_on_deity_id"
add_index "deity_deity_siblings", ["user_id"], name: "index_deity_deity_siblings_on_user_id"

create_table "deity_floras", force: :cascade do |t|
t.integer "user_id"
t.integer "deity_id"
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/deity_character_siblings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
deity_id:
character_sibling_id: 1
user_id:

two:
deity_id:
character_sibling_id: 1
user_id:
11 changes: 11 additions & 0 deletions test/fixtures/deity_deity_siblings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
deity_id:
deity_sibling_id: 1
user_id:

two:
deity_id:
deity_sibling_id: 1
user_id:
7 changes: 7 additions & 0 deletions test/models/deity_character_sibling_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class DeityCharacterSiblingTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/deity_deity_sibling_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class DeityDeitySiblingTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit 7a58736

Please sign in to comment.