ransack icon indicating copy to clipboard operation
ransack copied to clipboard

Rails 7.2 - LoadError: cannot load such file -- polyamorous/activerecord_7.2_ruby_2/join_association (LoadError)

Open EverardB opened this issue 1 year ago • 6 comments

Upgrade to rails 7.2 and you will get the following message whilst constructing the database...

bin/rails aborted! LoadError: cannot load such file -- polyamorous/activerecord_7.2_ruby_2/join_association (LoadError) Did you mean? polyamorous/activerecord_7.0_ruby_2/join_association polyamorous/activerecord_6.1_ruby_2/join_association polyamorous/activerecord_6.0_ruby_2/join_association

EverardB avatar Aug 26 '24 00:08 EverardB

It seems that this is a fairly important issue to fix... ransack can not be used out-of-the-box in any project from rails 7.1+

EverardB avatar Aug 26 '24 22:08 EverardB

https://github.com/activerecord-hackery/ransack/issues/1519#issuecomment-2380644532

PRs welcome

scarroll32 avatar Sep 28 '24 13:09 scarroll32

@scarroll32 Maybe it will help someone who is also debugging this issue.

Rails 7.2.1 Ruby 3.2.2

x = ArticleCategory.ransack(title_eq: 'Child category')
x.result

It produces the next SELECT "article_categories".* FROM "article_categories" /* loading for pp */ LIMIT $1 [["LIMIT", 11]]

It returns all of the records (should not).

Backtrace of the calls:

ransack-4.2.1/lib/ransack/adapters/active_record/base.rb:15

def ransack(params = {}, options = {})
  Search.new(self, params, options)
end

ransack-4.2.1/lib/ransack/search.rb:43

def result(opts = {})
  @context.evaluate(self, opts)
end

ransack-4.2.1/lib/ransack/adapters/active_record/context.rb:27

def evaluate(search, opts = {})
  viz = Visitor.new
  relation = @object.where(viz.accept(search.base))
   ...
end

ransack-4.2.1/lib/ransack/visitor.rb viz.accept will call visit method here:

def visit(object)
  send(DISPATCH[object.class], object)
end

and this will call visit_Ransack_Nodes_Condition and visit_Ransack_Nodes_Grouping.

The strange behavior that I noticed is that Ransack::Nodes::Condition does not have attributes, it returns an empty array. I read test cases so probably it is not correct behavior, also I run tests locally and they are all green, so the current issue is not covered by them.

dmytro-strukov avatar Oct 08 '24 11:10 dmytro-strukov

@EverardB Which versions of Ransack and Rails do you use?

dmytro-strukov avatar Oct 09 '24 11:10 dmytro-strukov

Possible cause https://github.com/activerecord-hackery/ransack/blob/main/lib/polyamorous/polyamorous.rb#L19C1-L20C1

PRs welcome

scarroll32 avatar Oct 09 '24 12:10 scarroll32

@scarroll32 Could you please provide steps to reproduce the issue?

dmytro-strukov avatar Oct 09 '24 13:10 dmytro-strukov