Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Multiple Conditions with scopes #566

@the8472

Description

@the8472

The Defining Abilities wiki page states the following about using scopes:

You cannot use this with multiple can definitions that match the same action and model since it is not possible to combine them.

I would like to question this supposed impossibility.

Here is a quick proof of concept (read: hack) that can merge Hash and ActiveRecord::Relation conditions using arel 2.0.10 and cancan 1.6.7. It currently does not support negative abilities - which could be remedied by making the reduce phase a bit smarter - and always kicks in, even when no scopes are present.

All joins used in the scopes and hashes are also converted to outer joins since different joins may be necessary for different where conditions. This might have unintended side-effects and require an additional distinct/group by clause.

https://gist.github.com/1952018

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions