facet_for 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  module FacetFor
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/facet_for.rb CHANGED
@@ -101,7 +101,7 @@ module FacetFor
101
101
  # Ransack will then look at the _id column for the associated model.
102
102
  # This won't work properly on models with nonstandard id column
103
103
  # names. That's a problem, but whatevs for the time being.
104
-
104
+ @facet[:association_name] = "#{association.first.plural_name}"
105
105
  @facet[:column_name] = "#{association.first.plural_name}_id"
106
106
 
107
107
  elsif association.first.macro == :belongs_to
@@ -109,6 +109,7 @@ module FacetFor
109
109
  # If we're dealing with belongs_to, we can assume we just want
110
110
  # to look at the foreign key on the current model. Much simpler.
111
111
 
112
+ @facet[:association_name] = association.first.name
112
113
  @facet[:column_name] = association.first.foreign_key
113
114
 
114
115
  end
@@ -122,7 +123,9 @@ module FacetFor
122
123
  # If the user hasn't specified a collection, we'll provide one now
123
124
  # based on this association
124
125
 
125
- @facet[:collection] = @facet[:collection] || association.first.klass.all
126
+ @facet[:collection] = @facet[:model].joins(@facet[:association_name].to_sym).select("DISTINCT #{@facet[:column_name]}").where("#{@facet[:column_name]} IS NOT NULL").map { |m| m.send(@facet[:association_name].to_sym) }
127
+
128
+ # @facet[:collection] = @facet[:collection] || association.first.klass.all
126
129
  end
127
130
  else
128
131
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facet_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-05 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ransack
16
- requirement: &75492170 !ruby/object:Gem::Requirement
16
+ requirement: &72114110 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *75492170
24
+ version_requirements: *72114110
25
25
  description: Provides helpers for creating search forms with Ransack
26
26
  email:
27
27
  - jbarket@sleepunit.com
@@ -52,7 +52,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
52
52
  version: '0'
53
53
  segments:
54
54
  - 0
55
- hash: 625741645
55
+ hash: -223193421
56
56
  required_rubygems_version: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
61
  version: '0'
62
62
  segments:
63
63
  - 0
64
- hash: 625741645
64
+ hash: -223193421
65
65
  requirements: []
66
66
  rubyforge_project: facet_for
67
67
  rubygems_version: 1.8.10