EugZol / where_exists

Adds the power of SQL Exists to ActiveRecord
MIT License
110 stars 18 forks source link

Has and belongs to many wrong table name #17

Closed romeerez closed 5 years ago

romeerez commented 5 years ago

Hello and thanks for this very useful gem! Could you please replace here https://github.com/EugZol/where_exists/blob/master/lib/where_exists.rb#L158

join_table = [self.table_name, associated_model.table_name].sort.join("_")

to

join_table = association.join_table

because it doesn't works properly for models with modules such

class ModuleName::ModelName
  has_and_belong_to_many :other_model_in_this_module
end

Also this:

associated_join_ids = quote_table_and_column_name(join_table, "#{associated_model.name.downcase}_id")

to this: associated_join_ids = quote_table_and_column_name(join_table, association.association_foreign_key)

EugZol commented 5 years ago

Please check version ~> 1.2 – PR by @SampsonCrowley seems to have fixed that? Please feel free to reopen otherwise.