activerecord_follow_assoc 0.1.0 → 0.1.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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc13a864fee3460feeb38797a0a95dd93816110f888d45fbd6423fab825d4b56
|
4
|
+
data.tar.gz: 8009a86c5b5f8f30f6920954ac58af1765bd3085e3e069311d5711ff20632740
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 845ad4b08f3160bce65fd7872267c9bc7d1bbe286ffc47c850eef53313b69c42a999c0c77323651bebe8c512fecd111a6de7f20bf58aa0d0bdec3a2672b3d817
|
7
|
+
data.tar.gz: bf81aed74ebab4c6b1be90021ce76bb76d0392a9f10e4c1cb4f25f60699e783dade093492e04fbbb1b2a780ab2e11eee19ba2f57a24754c1ef67475df4c2eb20
|
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
|
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.1
|
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: 2023-11-11 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
|