association_scope 0.1.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -13
- data/lib/association_scope/version.rb +1 -1
- data/lib/association_scope.rb +3 -9
- metadata +22 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4e530681dac428e3085f151e36a1a44a1f04a82b7da9df1be7e76fd3d02b80e
|
4
|
+
data.tar.gz: 05e2cf1a4c61eaef59bf93933827c118fa945be2f60a7079b1cd937e013259b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03e14bf3ca5db469c9e253dead3b9953f13afc4f39bb485bd48dac4c7b549dfa850f9933ffe9045a6ee97543ea883b35d264f5956fac01d93156f66ebd4919e2
|
7
|
+
data.tar.gz: ad322f4d8fe5a3e2860f421216f79bf4c129d652b0466c234a47970a4327c23659651cc1bfb4e344f7fa75356b3afac768eac08a272873a71201ca76a6cb1671
|
data/README.md
CHANGED
@@ -29,7 +29,7 @@ When you have this problem, the AssociationScope gem is for you!
|
|
29
29
|
Add this line to your application's Gemfile:
|
30
30
|
|
31
31
|
```ruby
|
32
|
-
gem 'association_scope'
|
32
|
+
gem 'association_scope'
|
33
33
|
```
|
34
34
|
|
35
35
|
And then execute:
|
@@ -37,42 +37,50 @@ And then execute:
|
|
37
37
|
$ bundle
|
38
38
|
```
|
39
39
|
|
40
|
+
Or install it yourself as:
|
41
|
+
```bash
|
42
|
+
$ gem install association_scope
|
43
|
+
```
|
44
|
+
|
40
45
|
## Usage
|
41
|
-
After installation you can use `
|
46
|
+
After installation you can use `has_association_scope_on` in your models:
|
42
47
|
```ruby
|
43
48
|
class Topic < ApplicationRecord
|
44
49
|
belongs_to :user
|
45
|
-
|
50
|
+
has_association_scope_on [:user]
|
46
51
|
end
|
47
52
|
```
|
48
53
|
Now you can use your associations as scopes and chain other scopes with them.
|
49
|
-
|
54
|
+
You can write
|
50
55
|
```ruby
|
51
|
-
|
56
|
+
Topic.all.users
|
52
57
|
```
|
53
|
-
to retrieve
|
58
|
+
to retrieve the users of all of the topics of your application.
|
54
59
|
|
55
60
|
## Known Issues
|
56
61
|
* This gem works with `reflections`.
|
57
|
-
To make this work, the `
|
62
|
+
To make this work, the `has_association_scope_on` call has to be below your association definitions.
|
58
63
|
```ruby
|
59
64
|
# won't work
|
60
65
|
class Topic
|
61
|
-
|
66
|
+
has_association_scope_on [:user]
|
62
67
|
belongs_to :user
|
63
68
|
end
|
64
69
|
|
65
70
|
# works
|
66
71
|
class Topic
|
67
72
|
belongs_to :user
|
68
|
-
|
73
|
+
has_association_scope_on [:user]
|
69
74
|
end
|
70
75
|
```
|
71
|
-
*
|
72
|
-
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.
|
73
78
|
Workaround: Migrate JSON columns to JSONB.
|
74
79
|
* Error messages are not raised during application start, but on first instantiation, because of the order in which classes are loaded.
|
75
80
|
|
76
81
|
## Development
|
77
|
-
Clone
|
78
|
-
To use `rails console` you have to navigate to the dummy application
|
82
|
+
Clone this repository and run `bundle`.
|
83
|
+
To use `rails console` you have to navigate to the dummy application
|
84
|
+
```bash
|
85
|
+
$ cd spec/dummy
|
86
|
+
```
|
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,29 +1,29 @@
|
|
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.2
|
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
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: standard
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -31,7 +31,7 @@ dependencies:
|
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.1.6
|
34
|
-
type: :
|
34
|
+
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
@@ -45,13 +45,27 @@ dependencies:
|
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 0.9.26
|
48
|
-
type: :
|
48
|
+
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.9.26
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.10'
|
55
69
|
description: AssociationScope adds useful scopes targeting Associations in ActiveRecord.
|
56
70
|
email:
|
57
71
|
- accounts@datae.de
|