lib/pg_serializable/visitors/json.rb in pg_serializable-1.3.2 vs lib/pg_serializable/visitors/json.rb in pg_serializable-1.4.0
- old
+ new
@@ -3,23 +3,25 @@
class Json < Base
def visit_record(subject, trait: :default)
table_alias = next_alias!
klass = subject.class
+ base_class = klass.base_class
select_sql = json_build_object(visit(klass.trait_manager, trait: trait, table_alias: table_alias)).to_sql
- from_sql = klass.where(id: subject.id).limit(1).to_sql
+ from_sql = base_class.where(id: subject.id).limit(1).to_sql
- klass.select(select_sql).from("#{as(from_sql, table_alias)}")
+ base_class.select(select_sql).from("#{as(from_sql, table_alias)}")
end
def visit_relation(subject, table_alias: nil, trait: :default)
table_alias ||= next_alias!
klass = subject.klass
+ base_class = klass.base_class
select_sql = coalesce(json_agg(json_build_object(visit(klass.trait_manager, trait: trait, table_alias: table_alias)))).to_sql
from_sql = subject.to_sql
- klass.select(select_sql).from("#{as(from_sql, table_alias)}")
+ base_class.select(select_sql).from("#{as(from_sql, table_alias)}")
end
def visit_class(subject, trait: :default, **kwargs)
visit(subject.all, trait: trait, **kwargs)
end