lib/pg_serializable/visitors/json.rb in pg_serializable-1.3.0 vs lib/pg_serializable/visitors/json.rb in pg_serializable-1.3.1
- old
+ new
@@ -43,11 +43,12 @@
def visit_attribute(subject, table_alias: nil)
return visit_enum(subject, table_alias: table_alias) if subject.enum?
table_alias ||= alias_tracker
key = "\'#{subject.label}\'"
- val = "\"#{table_alias}\".\"#{subject.prc ? subject.prc.call(column_name) : subject.column_name}\""
+ column_name = "\"#{table_alias}\".\"#{subject.column_name}\""
+ val = subject.prc ? subject.prc.call(column_name) : column_name
"#{key}, #{val}"
end
def visit_enum(subject, table_alias: nil)
key = "\'#{subject.label}\'"
@@ -85,16 +86,18 @@
"\'#{subject.label}\', (#{query})"
end
def visit_has_many_through(subject, table_alias:, **kwargs)
current_alias = next_alias!
-
association = subject.association
through = association.through_reflection
source = association.source_reflection
join_name = source.collection? ? through.plural_name.to_sym : through.name
+ # needs work
where_clause = begin
- if through.belongs_to?
+ if source.belongs_to?
+ "#{table_alias}.#{through.join_foreign_key}=#{through.table_name}.#{through.join_primary_key}"
+ elsif through.belongs_to?
"#{table_alias}.#{through.join_foreign_key}=#{through.table_name}.#{subject.foreign_key}"
else
"#{through.table_name}.#{through.join_foreign_key}=#{table_alias}.#{subject.foreign_key}"
end
end