Skip to content

Commit 5552717

Browse files
committed
closes #194
1 parent 5f0e76c commit 5552717

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

ruby/hyper-model/lib/reactive_record/active_record/reactive_record/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def self.find_locally(model, attrs, new_only: nil)
7171
if (id_to_find = attrs[model.primary_key])
7272
!new_only && lookup_by_id(model, id_to_find)
7373
else
74-
@records[model].detect do |r|
74+
@records[model.base_class].detect do |r|
7575
(r.new? || !new_only) &&
7676
!attrs.detect { |attr, value| r.synced_attributes[attr] != value }
7777
end
@@ -150,7 +150,7 @@ def initialize(model, hash = {}, ar_instance = nil)
150150
@attributes = {}
151151
@changed_attributes = []
152152
@virgin = true
153-
records[model] << self
153+
records[model.base_class] << self
154154
Base.set_object_id_lookup(self)
155155
end
156156

ruby/hyper-model/lib/reactive_record/active_record/reactive_record/lookup_tables.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ def class_scopes(model)
1414
end
1515

1616
def waiting_for_save(model)
17-
@waiting_for_save[model]
17+
@waiting_for_save[model.base_class]
1818
end
1919

2020
def wait_for_save(model, &block)
21-
@waiting_for_save[model] << block
21+
@waiting_for_save[model.base_class] << block
2222
end
2323

2424
def clear_waiting_for_save(model)
25-
@waiting_for_save[model] = []
25+
@waiting_for_save[model.base_class] = []
2626
end
2727

2828
def lookup_by_object_id(object_id)
@@ -33,8 +33,8 @@ def set_object_id_lookup(record)
3333
`#{@records_by_object_id}[#{record.object_id}] = #{record}`
3434
end
3535

36-
def lookup_by_id(*args) # model and id
37-
`#{@records_by_id}[#{args}]` || nil
36+
def lookup_by_id(model, id) # model and id
37+
`#{@records_by_id}[#{[model.base_class, id]}]` || nil
3838
end
3939

4040
def set_id_lookup(record)

ruby/hyper-model/spec/batch7/sti_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@ class Scoped < ActiveRecord::Base
130130

131131
end
132132

133+
it "Finders will work regardless of type" do
134+
Sti::SubClass1.create(data: 'changeme')
135+
expect_promise do
136+
Hyperstack::Model.load do
137+
Sti::Base.all.last
138+
end.then do |from_base|
139+
Hyperstack::Model.load do
140+
Sti::SubClass1.find(from_base.id)
141+
end.then do |from_subclass|
142+
from_subclass.data = 'changed'
143+
from_base.data
144+
end
145+
end
146+
end.to eq('changed')
147+
end
148+
133149
it "will use the subclass name to set the type" do
134150
evaluate_ruby('Sti::SubClass1.create(data: "record 1")')
135151
expect_promise('Sti::Base.last.load(:type)').to eq('Sti::SubClass1')
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class ActiveRecord::Base
2+
def new?
3+
raise 'Hypermodel internally using the deprecated new? method'
4+
end
5+
end

0 commit comments

Comments
 (0)