similar_models 0.2.0 → 0.2.1
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.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/similar_models.rb +1 -3
- data/lib/similar_models/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b55aa8e2b833092a963b70b211ff10f0ee78ead0
|
4
|
+
data.tar.gz: 264b408ebdb78c40b31a1c7f37c99cf6a0360c76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/similar_models.rb
CHANGED
@@ -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 =
|
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
|