Skip to content

Commit

Permalink
Move user_favorites to its own scope
Browse files Browse the repository at this point in the history
  • Loading branch information
ahukkanen committed Apr 5, 2024
1 parent bc52787 commit 1afdfe4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/decidim/favorites/favoritable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ module Favoritable
counter_cache: :favorites_count
)
has_many :favoriting, through: :favorites, source: :user
end

class_methods do
def user_favorites(user)
scope :user_favorites, lambda { |user|
includes(:favorites).where(
decidim_favorites_favorites: { decidim_user_id: user.id }
).order(favorites_order)
end
}
end

class_methods do
def favorites_order
"decidim_favorites_favorites.created_at DESC, #{table_name}.created_at DESC"
end
Expand Down

0 comments on commit 1afdfe4

Please sign in to comment.