Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jodosha/nested_models
NestedModels deal with massive handling of associated (nested) ActiveRecord models.
https://github.com/jodosha/nested_models
Last synced: about 1 month ago
JSON representation
NestedModels deal with massive handling of associated (nested) ActiveRecord models.
- Host: GitHub
- URL: https://github.com/jodosha/nested_models
- Owner: jodosha
- License: mit
- Created: 2009-01-14T15:29:44.000Z (almost 16 years ago)
- Default Branch: master
- Last Pushed: 2009-01-16T15:38:59.000Z (almost 16 years ago)
- Last Synced: 2024-10-21T17:54:50.791Z (2 months ago)
- Language: Ruby
- Homepage: http://lucaguidi.com/pages/nested_models
- Size: 94.7 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README
- Changelog: CHANGELOG
- License: MIT-LICENSE
Awesome Lists containing this project
README
NestedModels
============Until now ActiveRecord wasn't great with associations massive assignment (aka multi model forms handling).
This plugin allow to deal with this kind of problems.Example
=======class Project < ActiveRecord::Base
has_many :tasks, :accessible => true
end# CREATE
project = Project.create :name => "NestedModels", :tasks => [
{ :name => "Implement", :description => "Implement me" }
]project.name # => "NestedModels"
project.taks.size # => 1# UPDATE
project.update_attributes :tasks => [
{ :id => 1, :name => "Implement me" },
{ :name => "Evangelize", :description => "Tell to your friends!" }
]project.tasks.size # => 2
project.tasks.first.name # => "Implement me"
project.tasks.last.name # => "Evangelize"# DESTROY
project.update_attributes :tasks => [
{ :id => 1, :destroy => true }
]project.tasks.size # => 1
Note: you can define your own destroy flag:
class Milestone < ActiveRecord::Base
set_accessible_association_destroy_flag "destroy_me"
endproject.update_attributes :milestones => [
{ :id => 1, :destroy_me => true }
]Copyright (c) 2009 Luca Guidi, released under the MIT license