occams-record 0.32.0 → 0.33.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ebf460027823bcbce6742da3379158441a5d1ecc2e3a249f141d52d0f04454c
4
- data.tar.gz: 00ee095440ac326ed78a43f58474513d77d5451cddee473584a413085ed9c49a
3
+ metadata.gz: 79f596ff4340bb78be9568862a4e2ed4b170cc5e5433ea5e89d039e05d12b608
4
+ data.tar.gz: 461865caca31938b4edcef8ad8301654a78d0d7f335cef094b8e939c6a02bb5d
5
5
  SHA512:
6
- metadata.gz: 94d3d122f651516c41540fa76da6a70606ff7670ad6ca3b26e6e158cae272f96247e6228e96e0d6337b184377d9aad54cdaa647c4f6cfec21b70ca2825dc12e8
7
- data.tar.gz: dd24837a61b31bec5e8fcb2a5075fcf1b3803120b22e7fe839c7e5ee0688cb145c0e3ca52c82f703d61dc22cc4535e7e0d69810105c471eefb6af66552f9ffd3
6
+ metadata.gz: 3e2a1ed22da61aecccf805fbe5cfbae7abe4b9b49ffb55fc270f9166744d5e36eac8acbb4d0e6a4cb76da537a1f18daca40d28c574425d5cb12c658126f0a62c
7
+ data.tar.gz: ff1d5d5e82e39e88a7316905b9342209bd91c7c76a7b26418a48ae96344849701a4abcac2729980ace7a42be09ba6419360d49efeebde942b3e3838a9ef2c1db
@@ -31,6 +31,20 @@ module OccamsRecord
31
31
  # Build getters & setters for associations. (We need setters b/c they're set AFTER the row is initialized
32
32
  attr_accessor(*association_names)
33
33
 
34
+ # Build id getters for associations, e.g. "widget_ids" for "widgets"
35
+ self.associations.each do |assoc|
36
+ if (ref = model.reflections[assoc]) and !ref.polymorphic? and (ref.macro == :has_many or ref.macro == :has_and_belongs_to_many)
37
+ pkey = ref.association_primary_key.to_sym
38
+ define_method "#{assoc.singularize}_ids" do
39
+ begin
40
+ self.send(assoc).map(&pkey).uniq
41
+ rescue NoMethodError => e
42
+ raise MissingColumnError.new(self, e.name)
43
+ end
44
+ end
45
+ end
46
+ end if model
47
+
34
48
  # Build a getter for each attribute returned by the query. The values will be type converted on demand.
35
49
  model_column_types = model ? model.attributes_builder.types : {}
36
50
  self.columns.each_with_index do |col, idx|
@@ -3,5 +3,5 @@
3
3
  #
4
4
  module OccamsRecord
5
5
  # Library version
6
- VERSION = '0.32.0'.freeze
6
+ VERSION = '0.33.0'.freeze
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: occams-record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.32.0
4
+ version: 0.33.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordan Hollinger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-08 00:00:00.000000000 Z
11
+ date: 2018-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord