Archive for October, 2010

DataMapper update_or_create

October 13th, 2010

Source code: git repository at github
DataMapper has a defined method named first_or_create, very explicit name, that takes a condition and attributes as params. Its source code defined in dm-core-1.0.2/lib/dm-core/model.rb is:
def first_or_create(conditions = {}, attributes = {})
  first(conditions) || create(conditions.merge(attributes))
What is does is simply find the first resource by conditions, or create a new resource with the […]