effective_resources 0.3.7 → 0.3.8

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: eba61020b65a6e32afe9b254b63ea4566a5cceb8
4
- data.tar.gz: df4d4f4b07974c76c288524bd4961baef118e929
3
+ metadata.gz: 3d1402ecc05965bee97bc9bc54cab706bac0fed5
4
+ data.tar.gz: 3f6b2afd4c260dc4ecd7460e0ab68043b778509c
5
5
  SHA512:
6
- metadata.gz: 82609d5b75b873aa5a2cdf29e20f0c8226fd0fd956ebe53d2419601ace5985999a6eb79cf94c9992b808de9c0255fa7ca1858934b16e5b9b608d007efaff4bca
7
- data.tar.gz: de1464c94be8db959eb5fd245a157d30f107b95eea31ac1c15bafc37642a2194479c27c22fcd2cc5127c0381faba1361f1b86f92b1bd04374fa991c3fff3f48d
6
+ metadata.gz: 4f8fcd372c81a61cf1592533a4914bf1bfff2a7a0ccfd83eb385a798fb4e81d7f157e876b0e61c99897bf510ce64b68cc69920d68061abddfddd79f25e84275c
7
+ data.tar.gz: 9f20ffeb34e900ba6e48d593613c8aeb4be46a8463cc4cd31c052b2b8aa2b9844dca83bb6fb5a1c4124dbd8708c72f734a8a8c715ae530d5db6f0f05a144fdf2
@@ -5,6 +5,10 @@ module Effective
5
5
 
6
6
  # This is written for use by effective_logging and effective_trash
7
7
 
8
+ def instance
9
+ @instance || klass.new
10
+ end
11
+
8
12
  def instance_attributes
9
13
  return {} unless instance.present?
10
14
 
@@ -184,7 +184,7 @@ module Effective
184
184
  keys = klass.joins(association.name)
185
185
  .where(association.name => { association.source_reflection.klass.primary_key => values })
186
186
  .pluck(klass.primary_key)
187
- elsif association.macro == :has_many && association.options[:through].present?
187
+ elsif association.options[:through].present?
188
188
  key = sql_column(klass.primary_key)
189
189
 
190
190
  if association.source_reflection.options[:polymorphic]
@@ -201,7 +201,12 @@ module Effective
201
201
  scope = scope.where(association.source_reflection.foreign_type => reflected_klass.name)
202
202
  end
203
203
 
204
- keys = scope.pluck(association.through_reflection.foreign_key)
204
+ if association.through_reflection.macro == :belongs_to
205
+ key = association.through_reflection.foreign_key
206
+ keys = scope.pluck(association.through_reflection.klass.primary_key)
207
+ else
208
+ keys = scope.pluck(association.through_reflection.foreign_key)
209
+ end
205
210
  elsif association.macro == :has_many
206
211
  key = sql_column(klass.primary_key)
207
212
  keys = relation.pluck(association.foreign_key)
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '0.3.7'.freeze
2
+ VERSION = '0.3.8'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-28 00:00:00.000000000 Z
11
+ date: 2017-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails