active_hash_relation 1.0.3 → 1.0.4

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
  SHA1:
3
- metadata.gz: eb48b886a8ace57b0562d7e40bc60a10daf7fde3
4
- data.tar.gz: 6576b638fc3f6c21e5a3abfaa3d6329c7be6f8cc
3
+ metadata.gz: 2b6475c5d16eab20007e41f124b9db329cc9788a
4
+ data.tar.gz: 256afb180075bb73703f59bd5496aa4af6225f0b
5
5
  SHA512:
6
- metadata.gz: 626e25dd25e90c29a9360d986a8cfafa035ddc5822be42d38ada63ea61ab014b862f445db2ad68271cca1a2ecb2d8e519413a080b74bd2ecce8c12c772767bf9
7
- data.tar.gz: 44c97841194c7df3b8e8bece218123b4f1e77db0edb42bd9d21a19269912e3f40c017734739271695f449166e8a63d5cb696b58166385f34bcc5d501b970815a
6
+ metadata.gz: 6edc4a82cbd60e9f459d6490d09086ec7f224f9bc346555972b848bb6b4a2417e181a9b136c21699bbe48d90ac7608f201d9f2e6bb7a31be5836fd03a477aec2
7
+ data.tar.gz: f9ed814d95540090b83f7aa744583ffd655884784587442f0fe691f2866503197c2da359f638130e129e9448c1a3948594284121749411f73f91543103926d8b
data/README.md CHANGED
@@ -123,6 +123,22 @@ Scopes are supported via a tiny monkeypatch in the ActiveRecord's scope class me
123
123
 
124
124
  will run the `.planned` scope on the resource.
125
125
 
126
+ ### Unscoped assotiations
127
+ If you have a default scope in your models and you have a good reason to keep that, `active_hash_relation` provides an option to override it when filtering associations:
128
+
129
+ ```ruby
130
+ #config/initializers/active_hash_relation.rb
131
+ ActiveHashRelation.configure do |config|
132
+ config.use_unscoped = true
133
+ end
134
+ ```
135
+
136
+ You still have to provide the main model `active_hash_relation` runs as unscoped though.
137
+ ```ruby
138
+ apply_filters(Video.unscoped.all, {limit: 30, user: {country_code: 'SE'}})
139
+ #"SELECT \"videos\".* FROM \"videos\" INNER JOIN \"users\" ON \"users\".\"id\" = \"videos\".\"user_id\" WHERE (users.country_code ILIKE '%GR%') LIMIT 30"
140
+ ```
141
+
126
142
  ### Whitelisting
127
143
  If you don't want to allow a column/association/scope just remove it from the params hash.
128
144
 
@@ -1,5 +1,5 @@
1
1
  module ActiveHashRelation::AssociationFilters
2
- def filter_associations(resource, params, model: nil)
2
+ def filter_associations(resource, params, model = nil)
3
3
  unless model
4
4
  model = model_class_name(resource)
5
5
  end
@@ -58,8 +58,8 @@ module ActiveHashRelation
58
58
  end
59
59
 
60
60
 
61
- @resource = filter_scopes(@resource, @params[:scopes]) if @params.include?(:scopes)
62
- @resource = filter_associations(@resource, @params) if @include_associations
61
+ @resource = filter_scopes(@resource, @params[:scopes], @model) if @params.include?(:scopes)
62
+ @resource = filter_associations(@resource, @params, @model) if @include_associations
63
63
  @resource = apply_limit(@resource, @params[:limit]) if @params.include?(:limit)
64
64
  @resource = apply_sort(@resource, @params[:sort], @model) if @params.include?(:sort)
65
65
 
@@ -1,5 +1,5 @@
1
1
  module ActiveHashRelation::ScopeFilters
2
- def filter_scopes(resource, params, model: nil)
2
+ def filter_scopes(resource, params, model = nil)
3
3
  unless model
4
4
  model = model_class_name(resource)
5
5
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveHashRelation
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -35,8 +35,8 @@ module ActiveHashRelation
35
35
  ).apply_filters
36
36
  end
37
37
 
38
- def aggregations(resource, params)
39
- Aggregation.new(resource, params).apply
38
+ def aggregations(resource, params, model: nil)
39
+ Aggregation.new(resource, params, model: model).apply
40
40
  end
41
41
 
42
42
  class Configuration
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_hash_relation
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Filippos Vasilakis
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-10-08 00:00:00.000000000 Z
12
+ date: 2015-11-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler