active_record-mti 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: 184ec1c49f5ccb8a375f7780684e265bb4132b13
4
- data.tar.gz: 74679030c66bf141020f7e58c4aed0597cc83dd6
3
+ metadata.gz: cf67d3c346558b94eeaf4b68d354e4f29bcaa0b4
4
+ data.tar.gz: 29beb0dfeb868e4333add080161327582940ecf0
5
5
  SHA512:
6
- metadata.gz: 9e9d8a6e8f9b116529d648bed2893e8cf85f5c479791362d5dcd903fd502d012557dc8f1f46c4953e4fe0a2c6a982197efa3bf3bc52f46c8661adf788026bbb3
7
- data.tar.gz: b78dac12e338c6cb5d236efb59486b34dae3280902097b5daa03eb297513ab9eaff8e61619cec283c97acc56b818ad6e411460bd5fd42d4ade2f6e0b59c705e4
6
+ metadata.gz: ad4df7d52b11712e43a283d2e9008c7611f8bc7b96ae1545693e04a002fe694e38f7959b7f04f9fcf4aea76a0e9f8dfb110389b6fa6252ee001b636878706673
7
+ data.tar.gz: 5ea3c7c73e457bc10f16c69cc4b2a1f53b02f8c904e5cf7ccefb58ec568f4de6079bf2cebd1d512f62ad3940dc0129700ee0901e6e0040274f8356e91ba2f43e
@@ -33,12 +33,7 @@ module ActiveRecord
33
33
 
34
34
  module ClassMethods
35
35
 
36
- def inherited(child)
37
- super
38
- end
39
-
40
- def uses_mti(table_name = nil, inheritance_column = nil)
41
- # self.table_name ||= table_name
36
+ def uses_mti(custom_table_name = nil, inheritance_column = nil)
42
37
  self.inheritance_column = inheritance_column
43
38
 
44
39
  @uses_mti = true
@@ -49,7 +44,8 @@ module ActiveRecord
49
44
  end
50
45
 
51
46
  def uses_mti?
52
- @uses_mti ||= check_inheritence_of(@table_name)
47
+ @uses_mti = check_inheritence_of(@table_name) if @uses_mti.nil?
48
+ @uses_mti
53
49
  end
54
50
 
55
51
  private
@@ -58,16 +54,21 @@ module ActiveRecord
58
54
  return nil unless table_name
59
55
 
60
56
  result = connection.execute <<-SQL
61
- SELECT EXISTS ( SELECT 1
62
- FROM pg_catalog.pg_inherits
63
- WHERE inhrelid = 'public.#{table_name}'::regclass::oid
64
- OR inhparent = 'public.#{table_name}'::regclass::oid);
57
+ SELECT EXISTS (
58
+ SELECT 1
59
+ FROM pg_catalog.pg_inherits AS i
60
+ LEFT JOIN pg_catalog.pg_rewrite AS r ON r.ev_class = 'public.#{table_name}'::regclass::oid
61
+ LEFT JOIN pg_catalog.pg_depend AS d ON d.objid = r.oid
62
+ LEFT JOIN pg_catalog.pg_class AS cl_d ON cl_d.oid = d.refobjid
63
+ WHERE inhrelid = COALESCE(cl_d.relname, 'public.#{table_name}')::regclass::oid
64
+ OR inhparent = COALESCE(cl_d.relname, 'public.#{table_name}')::regclass::oid
65
+ );
65
66
  SQL
66
67
 
67
68
  # Some versions of PSQL return {"?column?"=>"t"}
68
- # instead of {"first"=>"t"}, so we're saying screw it,
69
+ # instead of {"exists"=>"t"}, so we're saying screw it,
69
70
  # just give me the first value of whatever is returned
70
- result.try(:first).try(:values).try(:first) == 't'
71
+ return result.try(:first).try(:values).try(:first) == 't'
71
72
  end
72
73
 
73
74
  # Called by +instantiate+ to decide which class to use for a new
@@ -30,7 +30,6 @@ module ActiveRecord
30
30
 
31
31
  "#{full_table_name_prefix}#{contained}#{undecorated_table_name(name)}#{full_table_name_suffix}"
32
32
  elsif uses_mti?
33
-
34
33
  # Nested classes are prefixed with singular parent table name.
35
34
  if superclass < Base && !superclass.abstract_class?
36
35
  contained = superclass.table_name
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module MTI
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record-mti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Stevens
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-12 00:00:00.000000000 Z
11
+ date: 2017-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg