Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Fixed build_join_dependency to handle Squeel's join nodes. #79

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

budu
Copy link

@budu budu commented Dec 3, 2011

This fix a compatibility issue with Squeel.

@ernie
Copy link
Contributor

ernie commented Dec 3, 2011

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?

@budu
Copy link
Author

budu commented Dec 3, 2011

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
Copy link
Author

budu commented Feb 3, 2012

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
Copy link
Author

budu commented Feb 3, 2012

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

@houen
Copy link

houen commented Mar 7, 2012

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}}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants