association_scope 0.2.0 → 0.3.0
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 +7 -7
- data/lib/association_scope/version.rb +1 -1
- data/lib/association_scope.rb +3 -9
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6737d583c54a2ce44c51f9313544bc2b73d5d083b86fa502b6e82bbca3c48d1
|
4
|
+
data.tar.gz: b85b28120cf9b7ac32a92f47db2ce4526391734188e9c13fcdfcb0762c177ba3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 162342ebf690b58e11a7ebb201073ac17bbeec4bd57e4b51c5f88a1ee2b1077182e98430e604d343fc31a237f615cafd7a736fcf99beb700dd4ee004d401d74f
|
7
|
+
data.tar.gz: 17e05e72a62217351f2d7bca06d6e0d2477ee9445df53cfb16681e728630cca3e6b2309b490fb50d6e5d6d175e1e0d7ecbb65fd81889eb54cdc714ff219006a9
|
data/README.md
CHANGED
@@ -43,11 +43,11 @@ $ gem install association_scope
|
|
43
43
|
```
|
44
44
|
|
45
45
|
## Usage
|
46
|
-
After installation you can use `
|
46
|
+
After installation you can use `has_association_scope_on` in your models:
|
47
47
|
```ruby
|
48
48
|
class Topic < ApplicationRecord
|
49
49
|
belongs_to :user
|
50
|
-
|
50
|
+
has_association_scope_on [:user]
|
51
51
|
end
|
52
52
|
```
|
53
53
|
Now you can use your associations as scopes and chain other scopes with them.
|
@@ -59,22 +59,22 @@ to retrieve the users of all of the topics of your application.
|
|
59
59
|
|
60
60
|
## Known Issues
|
61
61
|
* This gem works with `reflections`.
|
62
|
-
To make this work, the `
|
62
|
+
To make this work, the `has_association_scope_on` call has to be below your association definitions.
|
63
63
|
```ruby
|
64
64
|
# won't work
|
65
65
|
class Topic
|
66
|
-
|
66
|
+
has_association_scope_on [:user]
|
67
67
|
belongs_to :user
|
68
68
|
end
|
69
69
|
|
70
70
|
# works
|
71
71
|
class Topic
|
72
72
|
belongs_to :user
|
73
|
-
|
73
|
+
has_association_scope_on [:user]
|
74
74
|
end
|
75
75
|
```
|
76
|
-
*
|
77
|
-
To use `distinct` on rows, all values of this row must be of types other than
|
76
|
+
* Does not work for tables without primary key.
|
77
|
+
* To use `distinct` on rows, all values of this row must be of types other than JSON.
|
78
78
|
Workaround: Migrate JSON columns to JSONB.
|
79
79
|
* Error messages are not raised during application start, but on first instantiation, because of the order in which classes are loaded.
|
80
80
|
|
data/lib/association_scope.rb
CHANGED
@@ -15,15 +15,9 @@ end
|
|
15
15
|
|
16
16
|
module ActiveRecord
|
17
17
|
class Base
|
18
|
-
def self.
|
19
|
-
|
20
|
-
|
21
|
-
raise ArgumentError, "Don't use :only and :except together!" unless only == reflections.keys || except == []
|
22
|
-
|
23
|
-
only = only.map { |o| o.to_s }
|
24
|
-
except = except.map { |e| e.to_s }
|
25
|
-
|
26
|
-
::AssociationScope::Scope.inject_scopes(self, only - except)
|
18
|
+
def self.has_association_scope_on(models)
|
19
|
+
models = models.map(&:to_s)
|
20
|
+
::AssociationScope::Scope.inject_scopes(self, models)
|
27
21
|
end
|
28
22
|
end
|
29
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: association_scope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- datae
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: '0'
|
109
109
|
requirements: []
|
110
|
-
rubygems_version: 3.
|
110
|
+
rubygems_version: 3.1.4
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: AssociationScope adds useful scopes targeting Associations in ActiveRecord.
|