rails-models: add AttributeAssignment
This commit is contained in:
parent
3233a07ea6
commit
a513aab1e1
|
@ -68,12 +68,13 @@ item.serialize_hash
|
||||||
item.save
|
item.save
|
||||||
item.save! # Same as above, but raises an Exception
|
item.save! # Same as above, but raises an Exception
|
||||||
|
|
||||||
item.update name: "John"
|
item.update name: 'John' # Saves immediately
|
||||||
item.update!
|
item.update! name: 'John'
|
||||||
|
|
||||||
item.update_column :name, "John" # skips validations and callbacks
|
|
||||||
item.update_columns name: "John"
|
item.update_column :name, 'John' # skips validations and callbacks
|
||||||
item.update_columns! name: "John"
|
item.update_columns name: 'John'
|
||||||
|
item.update_columns! name: 'John'
|
||||||
|
|
||||||
item.touch # updates :updated_at
|
item.touch # updates :updated_at
|
||||||
item.touch :published_at
|
item.touch :published_at
|
||||||
|
@ -87,6 +88,15 @@ Model.create # Same an #new then #save
|
||||||
Model.create! # Same as above, but raises an Exception
|
Model.create! # Same as above, but raises an Exception
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### [AttributeAssignment](http://devdocs.io/rails/activerecord/attributeassignment)
|
||||||
|
|
||||||
|
```rb
|
||||||
|
item.attributes # #<Hash>
|
||||||
|
|
||||||
|
item.attributes = { name: 'John' } # Merges attributes in. Doesn't save.
|
||||||
|
item.assign_attributes name: 'John' # Same as above
|
||||||
|
```
|
||||||
|
|
||||||
### [Dirty](http://devdocs.io/rails/activerecord/dirty)
|
### [Dirty](http://devdocs.io/rails/activerecord/dirty)
|
||||||
|
|
||||||
```rb
|
```rb
|
||||||
|
|
Loading…
Reference in New Issue