ref: using inline scope values

main
Washington Botelho 2018-03-01 13:35:35 -03:00
parent 96a5f67221
commit c91d7dc150
No known key found for this signature in database
GPG Key ID: 5DE4F42A8F073617
1 changed files with 1 additions and 6 deletions

View File

@ -62,13 +62,8 @@ module Rating
dependent: :destroy
scope :order_by_rating, ->(column = :estimate, direction = :desc, scope: nil) {
scope_values = {
scopeable_id: scope&.id,
scopeable_type: scope&.class&.base_class&.name
}
includes(:rating_records)
.where(Rating.table_name => scope_values)
.where(Rating.table_name => { scopeable_id: scope&.id, scopeable_type: scope&.class&.base_class&.name })
.order("#{Rating.table_name}.#{column} #{direction}")
}
end