similar_models 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ad504d7a2e4aff75dc1c3ff6d48162110aaedcad
4
- data.tar.gz: 38cbf0ecea5b020f118845b893d59ab7bdb508c9
3
+ metadata.gz: b55aa8e2b833092a963b70b211ff10f0ee78ead0
4
+ data.tar.gz: 264b408ebdb78c40b31a1c7f37c99cf6a0360c76
5
5
  SHA512:
6
- metadata.gz: aebcd2acdddd464feedfc604300daf67add8022fa18920305f2849a31489f1dc8534ffe6eb21e02061be09ac89984194347f2997e496cd031a997b6988388864
7
- data.tar.gz: aacfe230c5415df95ef1f4253cb837b53d559b5e770ceafaea9794611f3733fdb9219886c3ce6ae4053a70cc40f1531babd464483d22f69dd870340183f2e2ba
6
+ metadata.gz: b81bfa56e0a7cfad7ca1c2e3e00d67645dcf18ef2c0e1726d8f23905ffceda65e1ee7d8a617f5e1af136c62a36cb0f20b85f6e9cac5a5792423c06d277e812c6
7
+ data.tar.gz: b2a2d671129e2bdc1498296b8ce299d599132f96751bb5227fa5a35458026b4fb6c13e01710a29502e047f0632a8484df506fbef0f29fb21e40cd85d11857652
data/README.md CHANGED
@@ -70,6 +70,12 @@ Note multiple associations do not work with sqlite.
70
70
 
71
71
  Because of the use of `group`, pagination is not supported.
72
72
 
73
+ ## In conjunction with acts-as-taggable-on
74
+
75
+ If you use https://github.com/mbleigh/acts-as-taggable-on/#usage and want to find related users say across multiple contexts:
76
+
77
+ user.similar_users.where(taggings: { context: %w(skills interests) })
78
+
73
79
  ## Contributing
74
80
 
75
81
  1. Fork it
@@ -25,14 +25,12 @@ module SimilarModels
25
25
 
26
26
  scope = self.class.select("#{table_name}.*, count(#{primary_key_ref}) AS #{as}_model_count").
27
27
  where.not(primary_key => self.id).order("#{as}_model_count DESC")
28
- group_by_clause = primary_key
28
+ group_by_clause = self.class.column_names.map { |column| "#{table_name}.#{column}"}.join(', ')
29
29
 
30
30
  # if there is only one many-to-many association no need to use UNION sql syntax
31
31
  if association_scopes.one?
32
32
  scope.merge(association_scopes.first).group(group_by_clause)
33
33
  else
34
- group_by_clause = self.class.column_names.join(', ')
35
-
36
34
  # see http://blog.ubersense.com/2013/09/27/tech-talk-unioning-scoped-queries-in-rails/
37
35
  scope.from("((#{association_scopes.map(&:to_sql).join(') UNION ALL (')})) AS #{table_name}").group(group_by_clause)
38
36
  end
@@ -1,3 +1,3 @@
1
1
  module SimilarModels
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: similar_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jolyon Pawlyn