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

Add option for accessible_by querying strategy #655

Merged
merged 18 commits into from
Dec 12, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
regression
  • Loading branch information
ghiculescu committed Oct 14, 2020
commit e5411d7fab595ba9d89452d9f7f918ed0539245e
2 changes: 1 addition & 1 deletion lib/cancan/model_adapters/active_record_4_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def matches_condition?(subject, name, value)
# 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_joins_relation(relation)
def build_joins_relation(relation, *where_conditions)
case CanCan.accessible_by_strategy
when :subquery
inner = @model_class.unscoped do
Expand Down
4 changes: 2 additions & 2 deletions lib/cancan/model_adapters/active_record_5_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def self.matches_condition?(subject, name, value)

private

def build_joins_relation(relation)
def build_joins_relation(relation, *where_conditions)
case CanCan.accessible_by_strategy
when :subquery
inner = @model_class.unscoped do
relation.left_joins(joins)
@model_class.left_joins(joins).where(*where_conditions)
end
@model_class.where(@model_class.primary_key => inner)

Expand Down
2 changes: 1 addition & 1 deletion lib/cancan/model_adapters/active_record_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def build_relation(*where_conditions)
return relation unless joins.present?

# subclasses must implement `build_joins_relation`
build_joins_relation(relation)
build_joins_relation(relation, *where_conditions)
end

# Returns the associations used in conditions for the :joins option of a search.
Expand Down