Association update and favorites method on User
This commit is contained in:
parent
6a00c60a33
commit
a45193d1b8
3 changed files with 8 additions and 0 deletions
|
|
@ -1,5 +1,6 @@
|
|||
class Favorite < ApplicationRecord
|
||||
belongs_to :user
|
||||
has_one :party
|
||||
|
||||
def party
|
||||
Party.find(self.party_id)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ class Party < ApplicationRecord
|
|||
##### ActiveRecord Associations
|
||||
belongs_to :user, optional: true
|
||||
belongs_to :raid, optional: true
|
||||
belongs_to :favorite, optional: true
|
||||
|
||||
has_many :characters, foreign_key: "party_id", class_name: "GridCharacter", dependent: :destroy
|
||||
has_many :weapons, foreign_key: "party_id", class_name: "GridWeapon", dependent: :destroy
|
||||
has_many :summons, foreign_key: "party_id", class_name: "GridSummon", dependent: :destroy
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ class User < ApplicationRecord
|
|||
|
||||
##### ActiveRecord Associations
|
||||
has_many :parties, dependent: :destroy
|
||||
has_many :favorites, dependent: :destroy
|
||||
|
||||
##### ActiveRecord Validations
|
||||
validates :username,
|
||||
|
|
@ -35,4 +36,8 @@ class User < ApplicationRecord
|
|||
|
||||
##### ActiveModel Security
|
||||
has_secure_password
|
||||
|
||||
def favorite_parties
|
||||
self.favorites.map { |favorite| favorite.party }
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue