lib/adaptive_alias/patches/base.rb in adaptive_alias-0.2.1 vs lib/adaptive_alias/patches/base.rb in adaptive_alias-0.2.2
- old
+ new
@@ -44,10 +44,13 @@
end
end
expected_association_err_msgs = [
"Mysql2::Error: Unknown column '#{klass.table_name}.#{current_column}' in 'where clause'".freeze,
+ ].freeze
+
+ expected_ambiguous_association_err_msgs = [
"Mysql2::Error: Unknown column '#{current_column}' in 'field list'".freeze,
].freeze
expected_attribute_err_msgs = [
"can't write unknown attribute `#{current_column}`".freeze,
@@ -65,10 +68,18 @@
end
@fix_association = proc do |relation, reflection, error|
next false if not patch.removable
next false if patch.removed
- next false if not expected_association_err_msgs.include?(error.message)
+
+ ambiguous = expected_ambiguous_association_err_msgs.include?(error.message)
+
+ if ambiguous
+ next false if relation and klass != relation.klass
+ next false if reflection and klass != reflection.klass
+ end
+
+ next false if not expected_association_err_msgs.include?(error.message) and not ambiguous
patch.remove!
if relation
relation.where_clause.send(:predicates).each do |node|