meta_search icon indicating copy to clipboard operation
meta_search copied to clipboard

Fixed build_join_dependency to handle Squeel's join nodes.

Open budu opened this issue 13 years ago • 5 comments

This fix a compatibility issue with Squeel.

budu avatar Dec 03 '11 22:12 budu

I don't see any tests for this fix -- how are you managing to push a Squeel join node through to build_join_dependency? Can you show a use case that fails without this patch?

ernie avatar Dec 03 '11 22:12 ernie

Well I'm not sure how I managed to push the Squeel join, this happen in a relatively complex bit of code.

My controller send a scope (some are made using Squeel, others are more simple) dynamically to the model, but that seems to happens only when the relation is already scoped with a specific scope:

  scope(:with_course_inscriptions,
        joins(:course) \
          .includes(:course) \
          .joins { inscriptions.outer } \
          .group { course_events.id })

  scope :with_not_enough_inscriptions, lambda {
    with_course_inscriptions \
      .having { count(inscriptions.id) < coalesce(courses.minimum_inscriptions, 1) } \
      .select { courses.minimum_inscriptions } \
      .select :id # for count
  }

This is then passed to meta_search and it complains about Squeel::Nodes::Join being an unknown class. I wonder if it has to do the the group clause, which doesn't seems well handled by AR (the count method for example return a Hash that will_paginate doesn't handle).

I'll see if I can narrow it down.

budu avatar Dec 03 '11 23:12 budu

Sorry, I still hadn't had the time to look further into this but while moving to Rails 3.2 I've checked that the bug is still there and here's the stacktrace, maybe it could be useful:

meta_search (1.1.3) lib/meta_search/builder.rb:279:in `build_join_dependency'
activesupport (3.2.1) lib/active_support/core_ext/enumerable.rb:27:in `group_by'
activesupport (3.2.1) lib/active_support/core_ext/enumerable.rb:26:in `each'
activesupport (3.2.1) lib/active_support/core_ext/enumerable.rb:26:in `group_by'
meta_search (1.1.3) lib/meta_search/builder.rb:268:in `build_join_dependency'
meta_search (1.1.3) lib/meta_search/builder.rb:39:in `initialize'
meta_search (1.1.3) lib/meta_search/searches/active_record.rb:42:in `new'
meta_search (1.1.3) lib/meta_search/searches/active_record.rb:42:in `search'
activerecord (3.2.1) lib/active_record/relation/delegation.rb:14:in `search'
activerecord (3.2.1) lib/active_record/relation.rb:240:in `scoping'
activerecord (3.2.1) lib/active_record/scoping.rb:98:in `with_scope'
activerecord (3.2.1) lib/active_record/relation.rb:240:in `scoping'
activerecord (3.2.1) lib/active_record/relation/delegation.rb:14:in `search'
app/controllers/intranet/base_controller.rb:21:in `course_events_scope'

budu avatar Feb 03 '12 21:02 budu

Strangely enough, Squeel doesn't appear anywhere in the stacktrace. I really don't get it!

budu avatar Feb 03 '12 21:02 budu

This happens to me when I use squeel in the join of a scope.

This doesn't work: scope :where_user_is_editor, lambda{|user| joins{charity_editors}.where{charity_editors.id == user.id}}

But this does: scope :where_user_is_editor, lambda{|user| joins(:charity_editors).where{charity_editors.id == user.id}}

houen avatar Mar 07 '12 15:03 houen