Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kaspernj optimised queries with left joins #512

Merged
merged 7 commits into from
Jun 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Unreleased

* Drop support for actions without a subject (andrew-aladev)
* Allow to add attribute-level rules (phaedryx)
* Removed eager loading of associations for ActiveRecord 5 (kaspernj)

2.2.0 (Apr 13th, 2018)

Expand Down
6 changes: 1 addition & 5 deletions lib/cancan/model_adapters/active_record_5_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ def self.matches_condition?(subject, name, value)

private

# As of rails 4, `includes()` no longer causes active record to
# look inside the where clause to decide to outer join tables
# you're using in the where. Instead, `references()` is required
# in addition to `includes()` to force the outer join.
def build_relation(*where_conditions)
relation = @model_class.where(*where_conditions)
relation = relation.includes(joins).references(joins) if joins.present?
relation = relation.left_joins(joins).distinct if joins.present?
relation
end

Expand Down
1 change: 0 additions & 1 deletion spec/cancan/model_adapters/active_record_4_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ class Child < ActiveRecord::Base
parent = Parent.create!
Child.create!(parent: parent, created_at: 1.hours.ago)
Child.create!(parent: parent, created_at: 2.hours.ago)

expect(Parent.accessible_by(@ability)).to eq([parent])
end
end
Expand Down