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

use group by in results returned by with_permissions_to #158

Open
dgm opened this issue Oct 26, 2012 · 3 comments
Open

use group by in results returned by with_permissions_to #158

dgm opened this issue Oct 26, 2012 · 3 comments

Comments

@dgm
Copy link

dgm commented Oct 26, 2012

Given a rule such as:

@@@
has_permission_on :children, :to => :read do
if_attribute :enrollments => {:session => {:yearly_site_funding => {:includes_special_funding => true}}}
end
@@@

Calling Child.with_permissions_to(:read) returns back multiple duplicates of children, since they can have multiple enrollments. In SQL, if I could tack on a 'group by "children.id"', it comes back without dups.

Granted, I'm still stuck on some older versions of software: DA is (0.5.2) , rails 2.3. Has this been addressed at all yet, or is there an easy solution?

@stffn
Copy link
Owner

stffn commented Jan 20, 2013

I'm hesitant in adding such a bold thing as group_by to every query. Do we really know what kind of group by is needed? If we cannot be entirely sure, I'd rather have the app dev add it.

@dgm
Copy link
Author

dgm commented May 5, 2014

Another solution to this problem would be to use the results of with_permissions_to as a subselect for another query, which would keep the permissions part separate from the application domain part.

@dgm
Copy link
Author

dgm commented May 5, 2014

As another example that works:

Enrollment.where(child_id: 19447, id: Enrollment.with_permissions_to(:read))

It's a little clunky, but this does yield the correct results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants