Skip to content

Commit

Permalink
made FF fit for Rails5
Browse files Browse the repository at this point in the history
  • Loading branch information
axelerator committed May 8, 2017
1 parent 398525a commit 4928853
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions forty_facets.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "minitest"
spec.add_development_dependency "sqlite3"
spec.add_development_dependency "coveralls"
spec.add_development_dependency "activerecord", "= 4.1.0"
#spec.add_development_dependency "byebug" # travis doenst like byebug
spec.add_development_dependency "activerecord", "~> 5.0"
spec.add_development_dependency "byebug" # travis doenst like byebug
end
8 changes: 4 additions & 4 deletions lib/forty_facets/filter/facet_filter_definition.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'byebug'

module FortyFacets
class FacetFilterDefinition < FilterDefinition

Expand Down Expand Up @@ -129,14 +131,12 @@ def build_scope
return Proc.new { |base| base } if empty?
Proc.new do |base|
base_table = definition.origin_class.table_name
join_name = [definition.association.name.to_s, base_table.to_s].sort.join('_')

primary_key_column = "#{base_table}.#{definition.origin_class.primary_key}"

subquery = base.joins(definition.joins).select(primary_key_column)
.where("#{join_name}.#{definition.association.foreign_key}" => values).uniq
matches_from_facet = base.joins(definition.joins).where("#{definition.association.klass.table_name}.#{definition.association.klass.primary_key}" => values).select(primary_key_column)

base.joins(definition.joins).where(primary_key_column => subquery.select(primary_key_column)).distinct
base.joins(definition.joins).where(primary_key_column => matches_from_facet).distinct
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/forty_facets/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module FortyFacets
VERSION = "0.1.4"
VERSION = "0.1.5"
end

0 comments on commit 4928853

Please sign in to comment.