Skip to content

pedromg/dm-core-update_or_create

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

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

No packages published

Languages