New method for DataMapper::Model similar to first_or_create, but that allows to update or create upon merge (or not) of conditions and attributes. Returns a DataMapper object.
pedromg/dm-core-update_or_create
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
DataMapper::Model - update_or_create(conditions = {}, attributes = {}, merger = true) method that allows a model to be: -updated with attributes, based on search conditions, or; -created upon previous merge (or not) of the conditions and attributes; Example: Article.update_or_create({:id => 10}, {:name => "Spirou meet Franquin}) - if Article with 'id' 10 exists then it will receive a new name - if Article with 'id' 10 doesn't exist, it will be created with {:id => 10, :name => "Spirou meet Franquin"} Article.update_or_create({:id => 11}, {:name => "Fantasio meet Franquin}, false) - if Article with 'id' 11 doesn't exist, it will be created with {:name => "Spirou meet Franquin"}
About
New method for DataMapper::Model similar to first_or_create, but that allows to update or create upon merge (or not) of conditions and attributes. Returns a DataMapper object.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published