Commit 05bfcf0
committed
Introduce
Largely inspired by the Active Record implementation, this commit
introduces support for assigning instances of objects to classes that
`include ActiveModel::Model`.
It aims to handle assignment of `_attributes`-suffixed values in an
ActionView- and ActionPack-compliant way:
```ruby
Author = Struct.new(:name)
Category = Struct.new(:name)
class Article
include ActiveModel::Model
include ActiveModel::NestedAttributes
attr_accessor :author
attr_accessor :tags
accepts_nested_attributes_for :author
accepts_nested_attributes_for :tags, class_name: Category
end
article = Article.new(
author_attributes: { name: "Pseudo Nym" },
tags_attributes: {
0 => { name: "actionview" },
1 => { name: "actionpack" },
}
)
article.author.name # => "Pseudo Nym"
article.tags.pluck(:name) # => ["actionview", "actionpack"]
```ActiveModel::NestedAttributes
1 parent 488a7ce commit 05bfcf0
File tree
5 files changed
+1162
-0
lines changed- activemodel
- lib
- active_model
- test/cases
- guides/source
5 files changed
+1162
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
1 | 33 | | |
2 | 34 | | |
3 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
0 commit comments