improve relations and scopes
This commit is contained in:
@@ -7,6 +7,10 @@ class Post < ApplicationRecord
|
||||
|
||||
validate :user, :limit_of_post_per_day
|
||||
|
||||
scope :by_user_follows, ->(user) {
|
||||
where(user_id: user.following_ids)
|
||||
}
|
||||
|
||||
def repost?
|
||||
kind == :quoted_post
|
||||
end
|
||||
|
||||
@@ -9,4 +9,9 @@ class User < ApplicationRecord
|
||||
}
|
||||
|
||||
has_many :posts
|
||||
|
||||
has_many :user_follows_following, class_name: 'UserFollow', foreign_key: :follower_id
|
||||
has_many :user_follows_followers, class_name: 'UserFollow', foreign_key: :followed_id
|
||||
has_many :following, through: :user_follows_following, source: :followed
|
||||
has_many :followers, through: :user_follows_followers, source: :follower
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user