Warning Older Docs! - You are viewing documentation for a previous released version of RhoMobile Suite.

Rhom API

Allows access to the Rhodes mini database object mapper, performing database operation on Rhodes model objects. See the Rhom examples for examples of the Rhom API.

As of Rhodes version 3.3.3, the Barcode, NFC, and Signature Capture APIs, as well as Rhom data encryption are removed from Rhodes. These features are only supported in Zebra RhoMobile Suite. If you wish to use these features, you will need to upgrade to RhoMobile Suite. Your application’s build.yml will also need to be modified to indicate the application type is ‘Rhoelements’. Additionally, a RhoElements license is required.

client_id

Returns the current sync client id.

modelname.client_id

clear_notification

Clear notification for the object. See the sync notification section for more details.

modelname.clear_notification

database_export

Creates a zip archive of a local database partition with all its blob objects, and returns a path to that zip archive.

Rhom::Rhom.database_export(partition)
partition a local database partition.

database_import

Imports the database and blob objects from a zip archive created with database_export. If the imported archive is inconsistent, or other failure occurs during the import process, the original database will be restored.

Rhom::Rhom.database_import(partition, path_to_zip)
partition the local database partition to be replaced by the zip.
path_to_zip path to the zip archive created with database_export.

delete_all

Delete all Rhodes model objects for a source, filtering by conditions. Click here for a Rhom delete_all example.

modelname.delete_all(:conditions, :op)
:conditions (optional) hash of attribute/values; delete only objects matching these criteria, such as :conditions => {'industry'=>'electronics'}.
:op (optional) operator, such as "OR" or "IN". Allows you to have more than one set of conditions.

destroy

Destroy a Rhodes model object. Click here for a Rhom destroy example.

modelname.destroy

find

Find Rhodes model objects. Click here for a Rhom find example.

modelname.find(argument list)

The argument list can consist of the following arguments.

:all returns all objects; can use optional :conditions.
:first returns first object matching :conditions.
:count returns the number of objects matching these :conditions.
:conditions (optional) hash of attribute/values. Also supports sql fragments (i.e. "name like 'rhomobile'") or sql fragment with binding (you have to define :select with sql queries) (i.e. ["name like ?", "'#{company#}'"]) Use a comma around string values.
:order (optional) attribute(s) to order the list.
:orderdir (optional) Order direction: 'ASC' ascending, 'DESC' descending. Default = 'ASC'.)
:select (optional) array of string attributes to return with the object. Useful if your model has many attributes and your query only needs a few of them.
:per_page (optional) maximum number of items to return.
:offset (optional) offset from beginning of the list.
:op (optional) operator, such as "OR" or "IN". Allows you to have more than one set of conditions.

For examples of find with advanced queries, see Advanced Queries in Using the Local Database with Rhom.

find_all

Alias for modelname.find(:all, argument list).

find_by_sql

Returns Rhodes model object(s) based on sql_query. This method works only for schema models. Click here for a Rhom find_by_sql example.

modelname.find_by_sql(sql_query)
sql_query An sql query, such as "SELECT * FROM Account".

get_source_id

Returns the source id number for this Rhodes model object.

modelname.get_source_id

get_source_name

Returns the source name for this Rhodes model object.

modelname.get_source_name

new

Create a new Rhodes model object. Rhom new example.

modelname.new(attributes)
attributes List of attributes assigned to the new model object, such as {"name" => "ABC Inc.","address" => "555 5th St."}.

create

Create a new Rhodes model object and save it to the database.Rhom create example.

This is the fastest way to insert a single item into the database.

modelname.create(attributes)
attributes List of attributes assigned to the new model object, such as {"name" => "ABC Inc.","address" => "555 5th St."}.

paginate

Call find with a limit on the number of records. Default page size is 10.Rhom paginate example.

modelname.paginate(*arguments)

The *arguments you can use are:

:page which page to return.
:per_page with :page (used as offset), the number of records to return, such as :page => 1, :per_page => 20
:conditions same as find with :conditions
:order same as find with :order
:select same as find with :select

sync

Start the sync process for a Rhodes model. Click here for a Rhom sync example.

modelname.sync(callback_url, callback_data, show_status_popup, query_params)
callback_url the url for the sync callback method. If this is used, SyncEngine.set_notification is called before SyncEngine.dosync.
callback_data Data for the callback method.
show_status_popup true if you want to show a popup window upon sync, false otherwise.
query_params Optional. a query to pass to the sync server. The query_params value must be URL encoded.

can_modify

Returns true if the Rhodes model object is not currently being synced (if it is being synced, you should disable editing of the object). Click here for a Rhom can_modify example.

Before displaying an edit page for an object, your application can check if the object is currently being accessed by the sync process. If it is, you should disable editing of the object. can_modify could return true, for example, on a new local record that was created and sent to the RhoConnect application, but no response has been received yet.

modelname.can_modify

changed?

Returns true if a Rhodes model object has local database changes that need to be synchronized, false otherwise. Click here for a Rhom changed? example.

modelname.changed?

save

Saves the current Rhodes model object to the database. Click here for a Rhom save example.

modelname.save

set_notification

Set a notification to be called when the sync is complete for this model. Click here for a Rhom set_notification example.

modelname.set_notification(callback_url, params)
callback_url the url for your sync is finished notification callback method.
params parameters for the callback method.

update_attributes

Updates the current Rho model object attributes and saves it to the database. This is the fastest way to add or update model attributes. Click here for a Rhom update_attributes example.

modelname.update_attributes(attributes)
attributes List of attributes and their updated values, such as {"name" => "ABC Inc.","address" => "555 5th St."}.

database_fullclient_reset_and_logout

Reset the Rhodes model database and logout. Equivalent to Rhom::Rhom.database_full_reset(true) followed by SyncEngine.logout.

database_full_reset

Deletes all records from the property bag and model tables. For examples, see Resetting the Database in Using the Local Database with Rhom.

Rhom::Rhom.database_full_reset(reset_client_info, reset_local_models)
reset_client_info true to clean the client_info table, false otherwise.
reset_local_models true to clean local (non-synced) models, false otherwise.

database_full_reset_and_logout

Perform a full reset, then logout the RhoConnect client.

Rhom::Rhom.database_full_reset_and_logout

database_local_reset

Reset only local (non-sync-enabled) models.

Rhom::Rhom.database_local_reset

metadata

Returns the metadata definition for a given model as a hash. Click here for a Rhom metadata example.

Product.metadata
#=> {'foo' => 'bar'}

metadata=(metadata_def)

Assigns the JSON metadata definition for a given model. Click here for a Rhom metadata example.

Product.metadata = { 'foo' => 'bar' }.to_json
metadata_def JSON string of the metadata definition
Back to Top