activerecord_follow_assoc 0.1.0 → 0.1.2
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c3e62bdc3a618ec8df6a5b54701734f8dd2895389018eb9fd68f750f71d1fe0
|
4
|
+
data.tar.gz: c3e258f8c744305d0d272f208456b7372979fed0c36543385612c585d0657fc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ae73f99a8d3f6e96487822b02a8d2757d427245c7e1041723d713ddd626f7d053a0318bdf5c4c6790ca29e2122b0028a59911275a73d157a6f3df16416fe50d
|
7
|
+
data.tar.gz: e9059d3925da935e71160d46ff75cfa0e34c27d33a0b02c28f1d02f67eed66b896aca87422563e0690084281d70302dc10ab1daf92f6ee4212bf64a1c0398d1a
|
data/README.md
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
This gem is still a work in progress. It hasn't been released yet.
|
2
|
-
|
3
1
|
# ActiveRecord Follow Assoc
|
4
2
|
|
5
3
|
![Test supported versions](https://github.com/MaxLap/activerecord_follow_assoc/workflows/Test%20supported%20versions/badge.svg)
|
@@ -15,7 +13,7 @@ Here's how this gem allows you to do it:
|
|
15
13
|
current_user.posts.recent.follow_assoc(:comments)
|
16
14
|
```
|
17
15
|
|
18
|
-
The `follow_assoc` method, added by this gem allows you to query the specified association
|
16
|
+
The `follow_assoc` method, added by this gem, allows you to query the specified association
|
19
17
|
of the records that the current query would return.
|
20
18
|
|
21
19
|
Here is a more complete [introduction to this gem](INTRODUCTION.md).
|
@@ -46,7 +44,6 @@ Doing this without follow_assoc can be verbose, error-prone and less efficient d
|
|
46
44
|
|
47
45
|
## Installation
|
48
46
|
|
49
|
-
**This is not released yet. This won't work.**
|
50
47
|
Rails 4.1 to 6.1 are supported with Ruby 2.1 to 3.0. Tested against SQLite3, PostgreSQL and MySQL. The gem
|
51
48
|
only depends on the `activerecord` gem.
|
52
49
|
|
@@ -125,9 +122,7 @@ It allows you to make conditions based on your associations (without changing th
|
|
125
122
|
Post.where_assoc_exists([:comments, :author], &:admins)
|
126
123
|
```
|
127
124
|
|
128
|
-
This could be done with `follow_assoc`: `User.admins.follow_assoc(:comments, :post)`. But if you wanted conditions on
|
129
|
-
a second association, then `follow_assoc` wouldn't work. It all depends on the context where you need to do the query
|
130
|
-
and what starting point you have.
|
125
|
+
This could be done with `follow_assoc`: `User.admins.follow_assoc(:comments, :post)`. But if you wanted conditions on a second association, then `follow_assoc` wouldn't work. On the other hand, if you received a scope on users and wanted their posts, then `follow_assoc` would be a nicer tool for the job. It all depends on the context where you need to do the query and what starting point you have.
|
131
126
|
|
132
127
|
## Development
|
133
128
|
|
@@ -61,6 +61,16 @@ module ActiveRecordFollowAssoc
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
if ActiveRecord.gem_version >= Gem::Version.new("7.1.0.alpha")
|
65
|
+
def self.null_relation?(reflection)
|
66
|
+
reflection.null_relation?
|
67
|
+
end
|
68
|
+
else
|
69
|
+
def self.null_relation?(reflection)
|
70
|
+
reflection.is_a?(ActiveRecord::NullRelation)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
64
74
|
if ActiveRecord.gem_version >= Gem::Version.new("5.0")
|
65
75
|
def self.parent_reflection(reflection)
|
66
76
|
reflection.parent_reflection
|
@@ -10,7 +10,7 @@ module ActiveRecordFollowAssoc
|
|
10
10
|
# => "EXISTS (SELECT... *relation1*) OR EXISTS (SELECT... *relation2*)"
|
11
11
|
def self.sql_for_any_exists(relations)
|
12
12
|
relations = [relations] unless relations.is_a?(Array)
|
13
|
-
relations = relations.reject { |rel|
|
13
|
+
relations = relations.reject { |rel| ActiveRecordCompat.null_relation?(rel) }
|
14
14
|
sqls = relations.map { |rel| "EXISTS (#{rel.select('1').to_sql})" }
|
15
15
|
if sqls.size > 1
|
16
16
|
"(#{sqls.join(" OR ")})" # Parens needed when embedding the sql in a `where`, because the OR could make things wrong
|
@@ -165,7 +165,7 @@ module ActiveRecordFollowAssoc
|
|
165
165
|
|
166
166
|
if poly_belongs_to?(actual_source_reflection)
|
167
167
|
if reflection.options[:source_type]
|
168
|
-
|
168
|
+
reflection.options[:source_type].safe_constantize
|
169
169
|
else
|
170
170
|
if on_poly_belongs_to.nil?
|
171
171
|
msg = String.new
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord_follow_assoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maxime Lapointe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -189,7 +189,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
189
189
|
- !ruby/object:Gem::Version
|
190
190
|
version: '0'
|
191
191
|
requirements: []
|
192
|
-
rubygems_version: 3.
|
192
|
+
rubygems_version: 3.4.10
|
193
193
|
signing_key:
|
194
194
|
specification_version: 4
|
195
195
|
summary: Follow associations within your ActiveRecord queries
|