Skip to content

Commit

Permalink
Merge branch 'fix-ambiguous-columns' of https://github.com/aha-app/surus
Browse files Browse the repository at this point in the history
 into aha-app-fix-ambiguous-columns
  • Loading branch information
jackc committed May 5, 2017
2 parents 4c0c7c5 + e0f9b84 commit b7d8732
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/surus/json/belongs_to_scope_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ class BelongsToScopeBuilder < AssociationScopeBuilder
def scope
s = association
.klass
.where("#{quote_column_name association.active_record_primary_key}=#{quote_column_name association.foreign_key}")
.where("#{association_primary_key}=#{association_foreign_key}")
s = s.instance_eval(&association.scope) if association.scope
s
end

def association_primary_key
"#{association.quoted_table_name}.#{quote_column_name association.active_record_primary_key}"
end

def association_foreign_key
"#{outside_class.quoted_table_name}.#{quote_column_name association.foreign_key}"
end
end
end
end
2 changes: 1 addition & 1 deletion lib/surus/json/has_many_scope_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def outside_primary_key
end

def association_foreign_key
"#{connection.quote_column_name association.foreign_key}"
"#{association.quoted_table_name}.#{connection.quote_column_name association.foreign_key}"
end
end
end
Expand Down

0 comments on commit b7d8732

Please sign in to comment.