added validations and everything
This commit is contained in:
parent
57c4578533
commit
eecdecfda9
|
@ -1,2 +1,6 @@
|
||||||
class Relationship < ActiveRecord::Base
|
class Relationship < ActiveRecord::Base
|
||||||
|
belongs_to :source, class_name: 'User'
|
||||||
|
belongs_to :target, class_name: 'User'
|
||||||
|
validates :source_id, presence: true
|
||||||
|
validates :target_id, presence: true
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,6 +11,14 @@ class User < ActiveRecord::Base
|
||||||
has_many :answers, dependent: :destroy
|
has_many :answers, dependent: :destroy
|
||||||
has_many :comments, dependent: :destroy
|
has_many :comments, dependent: :destroy
|
||||||
has_many :inboxes, dependent: :destroy
|
has_many :inboxes, dependent: :destroy
|
||||||
|
has_many :active_relationships, class_name: 'Relationship',
|
||||||
|
foreign_key: 'source_id',
|
||||||
|
dependent: :destroy
|
||||||
|
has_many :passive_relationships, class_name: 'Relationship',
|
||||||
|
foreign_key: 'target_id',
|
||||||
|
dependent: :destroy
|
||||||
|
has_many :friends, through: :active_relationships, source: :target
|
||||||
|
has_many :followers, through: :passive_relationships, source: :source
|
||||||
|
|
||||||
SCREEN_NAME_REGEX = /\A[a-zA-Z0-9_]{1,16}\z/
|
SCREEN_NAME_REGEX = /\A[a-zA-Z0-9_]{1,16}\z/
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue