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

with_role returns readonly models in Rails 4 #175

Closed
D1plo1d opened this issue Aug 16, 2013 · 2 comments
Closed

with_role returns readonly models in Rails 4 #175

D1plo1d opened this issue Aug 16, 2013 · 2 comments

Comments

@D1plo1d
Copy link

D1plo1d commented Aug 16, 2013

Rails 4 now marks any model retrieved by a query including a join as readonly. This in turn causes a ActiveRecord::ReadOnlyRecord to be raised whenever a resource is returned from with_role.

The problem seems to be here: https://github.com/EppO/rolify/blob/master/lib/rolify/adapters/active_record/resource_adapter.rb#L7

Related: http://stackoverflow.com/a/639844

@D1plo1d
Copy link
Author

D1plo1d commented Aug 16, 2013

This can be fixed by adding a .readonly(false) to the query. I'm not sure if this should be patched in rolify.

@EppO
Copy link
Member

EppO commented Aug 23, 2013

Nice catch, I'll write a failing spec scenario and investigate for a workaround. A cleaner way seems to chain a select method to the query on the resource fields.

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

No branches or pull requests

2 participants