Skip to content

Commit a159ad0

Browse files
authored
fix(sti): remove unnecessary sti detection and always use actual model instead of parent (#579)
1 parent b853480 commit a159ad0

File tree

1 file changed

+1
-28
lines changed

1 file changed

+1
-28
lines changed

app/services/forest_liana/schema_utils.rb

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ def self.find_model_from_collection_name(collection_name, logs = false)
3131
if model.abstract_class?
3232
model_found = self.find_model_from_abstract_class(model, collection_name)
3333
elsif ForestLiana.name_for(model) == collection_name
34-
if self.sti_child?(model)
35-
model_found = model
36-
else
37-
model_found = model.base_class
38-
end
34+
model_found = model
3935
end
4036

4137
break if model_found
@@ -90,28 +86,5 @@ def self.habtm?(model)
9086
def self.is_active_type? model
9187
Object.const_defined?('ActiveType::Object') && model < ActiveType::Object
9288
end
93-
94-
def self.sti_child?(model)
95-
begin
96-
parent = model.try(:superclass)
97-
return false unless parent.try(:table_name)
98-
99-
if ForestLiana.name_for(parent)
100-
inheritance_column = parent.columns.find do |column|
101-
(parent.inheritance_column && column.name == parent.inheritance_column)\
102-
|| column.name == 'type'
103-
end
104-
105-
return inheritance_column.present?
106-
end
107-
rescue NoMethodError
108-
# NOTICE: ActiveRecord::Base throw the exception "undefined method
109-
# `abstract_class?' for Object:Class" when calling the existing method
110-
# "table_name".
111-
return false
112-
end
113-
114-
return false
115-
end
11689
end
11790
end

0 commit comments

Comments
 (0)