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

Conversation

@ghost
Copy link

@ghost ghost commented Aug 22, 2012

There are two issues with the current way cancan handles associations:

  1. Records are returned multiple times in some circumstances
  2. Several defined abilities prevent some records to show up under certain circumstances

This commit includes tests for both cases. It fixes both problems by changing joins to includes for the AR adapters. This could have performance implications, since includes will also select all columns in the associated records. We tried various ways of achieving the same thing using Arel directly, but were unable to make this work due to lack of support for outer joins in Rails 3.1.

This closes issues #724, #566 and #613

There are two issues with the current way cancan handles associations:

1) Records are returned multiple times in some circumstances
2) Several defined abilities prevent some records to show up under certain circumstances

This commit includes tests for both cases. It fixes both problems by changing `joins` to `includes` for the AR adapters. This could have performance implications, since `includes` will also select all columns in the associated records. We tried various ways of achieving the same thing using Arel directly, but were unable to make this work due to lack of support for outer joins in Rails 3.1.

This closes issues ryanb#724, ryanb#566 and ryanb#613
@travisbot
Copy link

This pull request passes (merged 2ffdf46 into b4285ae).

@heliostatic
Copy link

+1 for this PR. Currently I'm working around by chaining uniq every time I call accessible_by in one of these cases.

@jnicklas
Copy link

If you don't mind the extra dependency, I wrote this in the meantime, which adds outer joins: https://github.com/elabs/ar_outer_joins

This solves the problem even better because it doesn't have the ugly side effect of affecting the select clause.

In that case uniq needs to be added the query as well.

@stevenpetryk
Copy link

+1

@jnicklas
Copy link

@ryanb why did you pull in 02841bbc195cdb17c6a4f511da44e0040e80f5f7, when this does the exact same change, except this also adds tests for the incorrect behaviour?

@natebird
Copy link

@jnicklas You are right. This should be the pull request to pull in. Or at least pull in the specs.

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.

5 participants