Skip to content

Instantly share code, notes, and snippets.

@rupurt
Last active May 19, 2016 12:46
Show Gist options
  • Select an option

  • Save rupurt/182a474bb9889b54fa50ec5bc0445014 to your computer and use it in GitHub Desktop.

Select an option

Save rupurt/182a474bb9889b54fa50ec5bc0445014 to your computer and use it in GitHub Desktop.
includes AR weirdness
# Should be 8 records
ActiveRecord::Base.connection.execute(MembershipSummary.includes(:person).where(school_id: 2, group_id: 1).order("people.first_name asc NULLS LAST, person_id asc NULLS LAST").to_sql).count
# Should be 8 records but only returns 1
MembershipSummary.includes(:person).where(school_id: 2, group_id: 1).order("people.first_name asc NULLS LAST, person_id asc NULLS LAST").to_a.size
# 'joins' does what we want and returns 8 records. Maybe we can figure out how to get ransack to do a join instead of includes
MembershipSummary.joins(:person).where(school_id: 2, group_id: 1).order("people.first_name asc NULLS LAST, person_id asc NULLS LAST").to_a.size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment