Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11084 (closed enhancement: fixed)

Opened 3 months ago

Last modified 3 months ago

[PATCH] Add readonly option to all associations

Reported by: miloops Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: normal Keywords:
Cc:

Description

In several projects, I ran across some has_many associations that should only exist as read-only.

In the Active::Record.find method you can specify the readonly option providing a colletion of readonly objects. With this enhancement you may specify accessiblity at a higher scope, in a DRY way, providing more security while, at the same time, being able to establish read-only access in the model class.

Attachments

add_readonly_option_to_has_many_associations.diff (4.2 kB) - added by miloops on 02/12/08 00:16:25.
add_readonly_option_to_all_associations.diff (12.4 kB) - added by miloops on 02/13/08 02:06:21.
Added readonly parameter to all associations

Change History

02/12/08 00:16:25 changed by miloops

  • attachment add_readonly_option_to_has_many_associations.diff added.

02/12/08 23:08:48 changed by danger

I've never needed to do this but it's a rather trivial extension to the associations and it makes sense.

What I'd prefer to see instead of this is for it to work for all associations and, ultimately, for all associations to accept the same options as AR:Base.find accepts.

02/13/08 02:04:38 changed by miloops

  • summary changed from [PATCH] Add readonly option to has_many to [PATCH] Add readonly option to all associations.

I got the same recommendation in rails-contrib, so i added the same funcionality to all associations including docs and tests.

As you said danger, is a trivial extension and the new added lines are almost all tests and doc.

02/13/08 02:06:21 changed by miloops

  • attachment add_readonly_option_to_all_associations.diff added.

Added readonly parameter to all associations

02/13/08 02:18:05 changed by matt

+1 not super useful but I guess it makes sense to protect your model.

02/13/08 06:32:53 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [8864]) Introduce the :readonly option to all associations. Records from the association cannot be saved. Closes #11084.