query_helper 0.1.8 → 0.2.0

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: ee722b53cba3c6bbb0657b9102e0f5a46bf15d8f8d4c661b2acd7ff1374e8b9f
4
- data.tar.gz: c8749dbd254d793f8c864cd7fc85cbf6d38d8738ad8493fc54970c3e169e5915
3
+ metadata.gz: cd74e8f24a4e6841f6bc0049c4cc729366114be762ccd79e065153dd356149ff
4
+ data.tar.gz: 7cd75d322863e367a0e623a1bc6f2fdc25ce397bd77352a32b4332e294f5711e
5
5
  SHA512:
6
- metadata.gz: 25116ab59d1f2f3f95a6741f5f17f9864436da4690f89e6ef12d770c16ecf0195eaae20c24b10cdb028e94fbac4bd1ed0317eac8985abba69cf575e02ed975ff
7
- data.tar.gz: 0e734d5bbbcadfbbb734f9b8986d97eb85e81273901aeae90780523eb08a6aa8b9edbb10b930fb3623ee12d653b8185e4e034e89d458c33ce632ae1dc144609f
6
+ metadata.gz: c5ded16d1e131486949a1e5fb50622da80c1f0706fb4e1c466de98a0f631f2a7942baa90b44f6f666196c4aa711b317e86781edb79150c65a27c7fb6b83ac469
7
+ data.tar.gz: e481b684c397d872c9d0f1e383078f2f127f3eb0dc7a9c34f3eef3aac341849890322f5bff0a7f3d31a42dcec6d9c5cf2ba5988655e6a01de5da07712d10a0d3
data/README.md CHANGED
@@ -35,7 +35,7 @@ Adding this code creates a `QueryHelper` object preloaded with pagination, filte
35
35
 
36
36
  ### Step 2: Use QueryHelper to run active record and sql queries within your controller
37
37
 
38
- #### Active Record Example
38
+ #### Raw SQL Example
39
39
 
40
40
  ```ruby
41
41
  class ResourceController < ApplicationController
@@ -53,26 +53,20 @@ class ResourceController < ApplicationController
53
53
  end
54
54
  ```
55
55
 
56
- #### Raw SQL Example
56
+ #### ActiveRecord Example
57
57
 
58
58
  ```ruby
59
59
  class ResourceController < ApplicationController
60
60
 
61
61
  def index
62
- @query_helper.query = Resource.all
62
+ @query_helper.update(query: Resource.all)
63
63
  render json: @query_helper.results()
64
64
  end
65
65
 
66
66
  end
67
67
  ```
68
68
 
69
- You can also use the `@query_helper.update()` method to update the QueryHelper with an ActiveRecord object
70
-
71
- ```ruby
72
- @query_helper.update(
73
- query: Resource.all
74
- )
75
- ```
69
+ *NOTE: Previous documentation stated you could simply run `@query_helper.query = Resource.all`. While this method still works, it will evaluate the ActiveRecord query causing it to hit the database twice. It is recommended that you always use the update method to avoid this inefficiency*
76
70
 
77
71
  ### Step 3: Paginate, Sort, Filter, and Include Associations using URL params
78
72
 
data/lib/query_helper.rb CHANGED
@@ -32,7 +32,7 @@ class QueryHelper
32
32
  preload: [] # preload activerecord associations - used instead of `associations` when you don't want them included in the payload
33
33
  )
34
34
  @query = query.class < ActiveRecord::Relation ? query.to_sql : query
35
- @model = query.class < ActiveRecord::Relation ? query.model : model
35
+ @model = query.class < ActiveRecord::Relation ? query.base_class : model
36
36
  @bind_variables = bind_variables
37
37
  @sql_filter = sql_filter
38
38
  @sql_sort = sql_sort
@@ -67,7 +67,7 @@ class QueryHelper
67
67
  preload: []
68
68
  )
69
69
  @query = query.class < ActiveRecord::Relation ? query.to_sql : query if query
70
- @model = query.class < ActiveRecord::Relation ? query.model : model if model || query
70
+ @model = query.class < ActiveRecord::Relation ? query.base_class : model if model || query
71
71
  @bind_variables.merge!(bind_variables)
72
72
  filters.each{ |f| add_filter(**f) }
73
73
  @associations = @associations | associations
@@ -85,7 +85,7 @@ class QueryHelper
85
85
  def query=(value)
86
86
  if value.class < ActiveRecord::Relation
87
87
  @query = value.to_sql
88
- @model = value.model
88
+ @model = value.base_class
89
89
  else
90
90
  @query = value
91
91
  end
@@ -1,3 +1,3 @@
1
1
  class QueryHelper
2
- VERSION = "0.1.8"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: query_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan McDaniel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-12 00:00:00.000000000 Z
11
+ date: 2019-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler