Skip to content
coffeencoke edited this page Aug 8, 2012 · 9 revisions

These are the methods provided by MinceDataModel to store and retrieve data from the configured data store.

Example usage:

TronLightCycles.push_to_array :travel_log, Time.now
# Returns the data store
data_store

# Adds data fields to the model and returns the current data fields
data_fields(*fields)

# Sets the name of the data collection or table name
data_collection(collection_name = nil)

# Saves a model to the data store and returns the primary key for the new record
store(model)

# Replaces a model in the data store with the given model
update(model)

# Updates a field with the given value for a specific model
update_field_with_value(id, field, value)

# Increments a field with the given amount for a specific model
increment_field_by_amount(id, field, amount)

# Removes a value from an array for a model
remove_from_array(id, field, value)

# Adds a value to an array for a model
push_to_array(id, field, value)

# Gets a model by id
find(id)

# Gets all models
all

# Gets all models where the given field has the given value   
all_by_field(field, value)

# Gets all models where the given set of fields and values exist
all_by_fields(hash)

# Gets a model where the given set of fields and values exist
find_by_fields(hash)

# Gets a model by a specific field and value
find_by_field(field, value)

# Gets all models where an array contains any of the given values
containing_any(field, values)

# Gets all models where the array contains the given value
array_contains(field, value)

# Delete a field
delete_field(field)

# Delete all records that match the given params
delete_by_params(params)
Clone this wiki locally