-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add deity and character siblings to deities
- Loading branch information
Showing
12 changed files
with
120 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
db/migrate/20180202055802_create_deity_character_siblings.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |