improve relations and scopes

This commit is contained in:
João Victor Geonizeli
2022-02-28 10:33:44 -03:00
parent e465123190
commit 7ea2d65fef
4 changed files with 62 additions and 0 deletions

View File

@@ -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

View File

@@ -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