NewORMModel

NewORMModel CoreAPI module

New implementation of the RHOM Model.

BETA VERSION - This API has not been officially released. It should not be used in a production environment.

Methods

anyChangedObjects
()

Checks whether the model has any changed objects.

Synchronous Return:

  • BOOLEAN

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.anyChangedObjects()
canModify
(STRING objId)

Checks whether the object can be modified.

Parameters

  • objId : STRING

Synchronous Return:

  • BOOLEAN

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.canModify(STRING objId)
can_modify
(STRING objId)
Deprecated

Checks whether the object can be modified.

Parameters

  • objId : STRING

Synchronous Return:

  • BOOLEAN

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.can_modify(STRING objId)
changed?
()
Deprecated

Returns true if a Rhodes model object has local database changes that need to be synchronized, false otherwise.

Synchronous Return:

  • BOOLEAN

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.changed?()
client_id
()
Deprecated

Returns the current sync client id.

Synchronous Return:

  • STRING

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.client_id()
count
()
Deprecated

Returns the number of objects in the named model.

Synchronous Return:

  • INTEGER

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.count()
create
(HASH attrs)

Create a new Rhodes model object and save it to the database. This is the fastest way to insert a single item into the database.

Parameters

  • attrs : HASH

    List of attributes assigned to the new model object, such as {name : “ABC Inc.”,address: “555 5th St.”}.

Synchronous Return:

  • OBJECT

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.create(HASH attrs)
deleteAll
(HASH params)
Deprecated

Delete all Rhodes model objects for a source filtering by conditions. This method accepts parameters as key-value pairs. It accept conditions as a parameter.

Parameters

  • params : HASH

    A hash-map with deleteAll arguments.

    • conditions : HASH Optional

      The attribute names and its respective values are passed as a key-value pair in this HASH. This will delete only the objects matching the criteria passed in the HASH.

Synchronous Return:

  • Void

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.deleteAll(HASH params)
delete_all
(HASH params)

Delete all Rhodes model objects for a source filtering by conditions. This method accepts parameters as key-value pairs. It accepts 2 keys- conditions and op.

Parameters

  • params : HASH

    A hash-map with deleteAll arguments.

    • conditions : HASH or ARRAY Optional

      The attribute names and its respective values are passed as a key-value pair in this HASH. This will delete only the objects matching the criteria passed in the HASH.Also supports sql fragment with binding(i.e. [“name=?”, “company_name”]

Synchronous Return:

  • Void

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.delete_all(HASH params)
enable
(STRING propertyName)

Sets model’s Boolean property to true (enables model’s property)

Parameters

  • propertyName : STRING

    Possible Values :

    fixed_schema

    To set the type of model as Fixed_schema.

    sync

    To make the model as user model.

    full_update

    To send all the attributes(changed/unchanged) to Rhoconnect when an object is updated.

    pass_through

    To keep the sensitive data out of redis server.

Synchronous Return:

  • Void

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.enable(STRING propertyName)
find
(STRING queryType, HASH queryOptions)

Find model objects.

Parameters

  • queryType : STRING

    Possible Values :

    all

    returns all objects; can use optional :conditions.

    first

    returns first object matching :conditions.

    count

    returns the number of objects matching these :conditions.

  • queryOptions : HASH

    An object of selection options

    • conditions : HASH or ARRAY Optional

      The attribute names and its respective values are passed as a key-value pair in this HASH that is required to find. Ex: conditions { name:‘Symbol’}. Also supports sql fragment with binding(i.e. [“name=?”, “company_name”]).

      • propertyName :

      • propertyValue :

    • order : STRING or ARRAY Optional

      Attribute(s) to order the list.

    • orderdir : STRING or ARRAY Optional

      Order direction.

      Possible Values :

      ASC

      Ascending order. (Default)

      DESC

      Descending Order

    • select : ARRAY 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.

Synchronous Return:

  • ARRAY

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.find(STRING queryType, HASH queryOptions)
find_all
()
Deprecated

find(‘all’) replaces the legacy ruby method find_all.

Synchronous Return:

  • HASH

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.find_all()
find_by_sql
(STRING sqlQuery)

Returns array of objects for the given model queried according to the specified SQL.

Parameters

  • sqlQuery : STRING

Synchronous Return:

  • ARRAY

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.find_by_sql(STRING sqlQuery)
get
(STRING propertyName)

Get the value of a property of the current model.Ex: myModel.get(‘name’); See also the vars() method.

Parameters

  • propertyName : STRING

    The name of the property you are trying to retrieve.

Synchronous Return:

  • STRING :

    Value of the specified property from the database.

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.get(STRING propertyName)
getAllProperties
(CallBackHandler callback)

This method will return all of object/value pairs for the propertyNames of the API class.

Parameters

  • callback : CallBackHandler Optional

Async Callback Returning Parameters: HASH

    • : STRING

Synchronous Return:

  • HASH :

    Map of all available properties

    : this method also supports async callbacks - check the Callback tab for callback return parameters.
    • : STRING

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.getAllProperties(CallBackHandler callback)
getBackendRefreshTime
()
Replaces: backend_refresh_time

Returns time string when the source has been synced.

Synchronous Return:

  • STRING

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.getBackendRefreshTime()
getBelongsTo
(STRING propertyName)

Returns info about model’s relationships with other models.

Parameters

  • propertyName : STRING

Synchronous Return:

  • ARRAY

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.getBelongsTo(STRING propertyName)
getCount
()
Replaces: count

Returns total number of objects for the model.

Synchronous Return:

  • INTEGER

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.getCount()
getModel
(STRING modelName)

getModel method returns instance of the ORMModel.

Parameters

  • modelName : STRING

    Name of the model you want returned.

Synchronous Return:

  • STRING :

    NewORMModel object.

    • Object : SELF_INSTANCE: Rho.NewORMModel

Method Access:

  • Class Method: This method can only be accessed via the API class object.
    • JavaScript: Rho.NewORMModel.getModel(STRING modelName)
    • Ruby: Rho::NewORMModel.getModel(STRING modelName)
getModelProperty
(STRING propertyName)

Returns info about model’s field property.

Parameters

  • propertyName : STRING

    The name of the property.

Synchronous Return:

  • HASH :

    Returns property name,type and option in the form of an HASH.

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.getModelProperty(STRING propertyName)
getProperties
(ARRAY arrayofNames, CallBackHandler callback)

This method will return a set of object/value pairs for the list of the propertyName that is passed in. The propertyNames must be a valid property of the API class.

Parameters

  • arrayofNames : ARRAY

    List of properties I want to know about

    • Object : STRING

  • callback : CallBackHandler Optional

Async Callback Returning Parameters: HASH

    • : STRING

Synchronous Return:

  • HASH :

    Map of properties I want to know about

    : this method also supports async callbacks - check the Callback tab for callback return parameters.
    • : STRING

Method Access:

  • Instance Method: This method can be accessed via an instance object of this class:
    • myObject.getProperties(ARRAY arrayofNames, CallBackHandler callback)
getProperty
(STRING propertyName, CallBackHandler callback)

This method will return the value of the propertyName that is passed in. The propertyName must be a valid property of the API class.

Parameters

  • propertyName : STRING

    The property to return info about.

  • callback : CallBackHandler Optional

Async Callback Returning Parameters: STRING

    Synchronous Return:

    • STRING :

      The property to return info about.

      : this method also supports async callbacks - check the Callback tab for callback return parameters.

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.getProperty(STRING propertyName, CallBackHandler callback)
    get_source_id
    ()
    Deprecated

    Returns the source id number for this Rhodes model object. Please use the model property source_id.

    Synchronous Return:

    • HASH

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.get_source_id()
    get_source_name
    ()
    Deprecated

    Returns the source name for this Rhodes model object. Please use the model property model_name.

    Synchronous Return:

    • HASH

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.get_source_name()
    has
    (STRING propertyName)

    Returns true if the model has the propertyName given.

    Parameters

    • propertyName : STRING

      The name of the property you are checking for its existence.

    Synchronous Return:

    • BOOLEAN

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.has(STRING propertyName)
    hasChanges
    (STRING objId)

    Checks whether the object has any changes. Returns true when an object is created or updated.

    Parameters

    • objId : STRING

    Synchronous Return:

    • BOOLEAN

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.hasChanges(STRING objId)
    make
    ()

    Create a new ORM model object JavaScript reference but does not save it to the database. To save this reference to the database, you will need to execute the .save() method.

    Synchronous Return:

    • Void

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.make()
    new
    (STRING modelName)

    Initializes new model’s instance.

    Parameters

    • modelName : STRING

    Synchronous Return:

    • Void

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.new(STRING modelName)
    onSyncCreateError
    (ARRAY objects, STRING action)

    Handles sync create errors.

    Parameters

    • objects : ARRAY

    • action : STRING

    Synchronous Return:

    • Void

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.onSyncCreateError(ARRAY objects, STRING action)
    onSyncDeleteError
    (STRING objId, HASH attrHash, STRING action)

    Handles sync delete errors for the object.

    Parameters

    • objId : STRING

    • attrHash : HASH

    • action : STRING

    Synchronous Return:

    • Void

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.onSyncDeleteError(STRING objId, HASH attrHash, STRING action)
    onSyncUpdateError
    (STRING objId, HASH attrHash, HASH rollbackHash, STRING action)

    Handles sync update errors for the object.

    Parameters

    • objId : STRING

    • attrHash : HASH

    • rollbackHash : HASH

    • action : STRING

    Synchronous Return:

    • Void

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.onSyncUpdateError(STRING objId, HASH attrHash, HASH rollbackHash, STRING action)
    paginate
    (HASH params)

    The paginate method takes care of setting the proper page limit and offset when a large number of records are fetched. This method accepts parameters as key-value pairs.

    Parameters

    • params : HASH

      A hash-map with paginate arguments.

      • page : INTEGER Optional

        This value is an offset which indicates the prevailing page number.

      • per_page : INTEGER Optional

        This value specifies number of records to be returned. The default value of per_page is 10.

      • conditions : ARRAY or HASH Optional

        hash of attribute/values. Also supports sql fragment with binding(i.e. [“name=?”, “company_name”]).

      • order : STRING or ARRAY Optional

        The attribute names to order the list.

      • orderdir : STRING or ARRAY Optional

        Order direction: ‘ASC’ ascending, ‘DESC’ descending. Default = ‘ASC’.

      • select : STRING Optional

        The array of string attributes to return with the object.

    Synchronous Return:

    • ARRAY

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.paginate(HASH params)
    pushChanges
    ()

    Pushes all changes for the source. For details push_changes

    Synchronous Return:

    • Void

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.pushChanges()
    push_changes
    ()
    Deprecated

    Pushes all changes for the source.

    Synchronous Return:

    • Void

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.push_changes()
    save
    ()

    Saves the object’s attributes in the DB.

    Synchronous Return:

    • Void

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.save()
    set
    (STRING propertyName, STRING propertyValue)

    Sets model’s property to value with additional processing for :sync property.

    Parameters

    • propertyName : STRING

      • partition : STRING

        The partition to use for this model. Partitions can be used to segment the data and keep non-synched data separate from synched models.

        Possible Values :

        local

        This partition is used automatically if the model is not a sync model.

        user

        This partition is used automatically if the model is a sync model.

        app

        This partition is used to store the application related information.

      • sync_type : STRING

        Sets the type of sync it will be.

        Possible Values :

        none

        If data model is not a sync model.

        incremental

        Used when the data model is a sync model. Just syncs changes.

        bulk_only

        If the model is used only for bulk sync.

      • sync_priority : INTEGER

        This number determines the order in which the models are processed and synchronised. Priority starts from lower value 1. Lower the number, higher is the priority. Default value is 1000.

      • freezed : BOOLEAN

        To make the model Freezed.

      • schema_version : FLOAT

        This is used for data migration of the application.

    • propertyValue : STRING

      The property names takes the corresponding property values, as mentioned above .

    Synchronous Return:

    • Void

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.set(STRING propertyName, STRING propertyValue)
    setBelongsTo
    (STRING propertyName, STRING sourceName)

    Using this method, you can set sync association between models. For details Associations

    Parameters

    • propertyName : STRING

    • sourceName : STRING

    Synchronous Return:

    • Void

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.setBelongsTo(STRING propertyName, STRING sourceName)
    setModelProperty
    (STRING propertyName, STRING propertyType, STRING propOption)

    Initializes new model’s field property.

    Parameters

    • propertyName : STRING

      The name of the property.

    • propertyType : STRING

      The type of property. Possible values are: String, Float, integer, Boolean, Varchar, Blob. String is default.

    • propOption : STRING Optional Default: Null

      Possible Values :

      overwrite

      Overwrite client copy of blob with the new copy from server. This is useful when RhoConnect modifies images sent from Rhodes, for example zooming or cropping.

    Synchronous Return:

    • Void

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.setModelProperty(STRING propertyName, STRING propertyType, STRING propOption)
    setProperties
    (HASH propertyMap)

    This method will set the values of a list of properties for the API class. The propertyName must be a valid property for the class and must also not be read only.

    Parameters

    • propertyMap : HASH

      Map of properties I want to set

      • Object : STRING

    Synchronous Return:

    • Void

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.setProperties(HASH propertyMap)
    setProperty
    (STRING propertyName, STRING propertyValue)

    This method will set the value of a property for the API class. The propertyName must be a valid property for the class and must also not be read only.

    Parameters

    • propertyName : STRING

      The one property name that I want to set

    • propertyValue : STRING

      The one property value that I want to set

    Synchronous Return:

    • Void

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.setProperty(STRING propertyName, STRING propertyValue)
    setSchemaIndex
    (STRING indexName, ARRAY indexCols, BOOLEAN is_unique)

    Initializes new model’s schema index.

    Parameters

    • indexName : STRING

      To define a named index on a set of attributes.

    • indexCols : ARRAY

      A set of attributes which need a indexName are passed through this array.

    • is_unique : BOOLEAN

      To make the indexCols as unique column is_unique is set to true. This will prevent inserting duplicate records.

    Synchronous Return:

    • Void

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.setSchemaIndex(STRING indexName, ARRAY indexCols, BOOLEAN is_unique)
    updateAttributes
    (HASH attributes)
    Deprecated

    Updates the current Rho model object attributes and saves it to the database. This is the fastest way to add or update model attributes.

    Parameters

    • attributes : HASH

      List of attributes and their updated values are passed as a key-value pair in this HASH.

    Synchronous Return:

    • Void

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.updateAttributes(HASH attributes)
    update_attributes
    (HASH 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.

    Parameters

    • attributes : HASH

      List of attributes and their updated values are passed as a key-value pair in this HASH.

    Synchronous Return:

    • Void

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.update_attributes(HASH attributes)
    vars
    ()

    Returns an object containing all propertyName and values for the model. You can use myModel.vars().name instead of myModel.get(‘name’).

    Synchronous Return:

    • HASH

    Method Access:

    • Instance Method: This method can be accessed via an instance object of this class:
      • myObject.vars()

    Properties

    associations
    : STRING

    Returns model’s associations.

    Property Access:

    • Instance: This property can be accessed via an instance object of this class:
      • myObject.associations
    fixed_schema
    : BOOLEAN

    Returns true if the model’s type is of fixed schema.

    Property Access:

    • Instance: This property can be accessed via an instance object of this class:
      • myObject.fixed_schema
    freezed
    : BOOLEAN

    Returns true if the model is frozen.

    Property Access:

    • Instance: This property can be accessed via an instance object of this class:
      • myObject.freezed
    loaded
    : BOOLEAN

    Returns true if model is loaded.

    Property Access:

    • Instance: This property can be accessed via an instance object of this class:
      • myObject.loaded
    model_name
    : STRING

    Returns model’s name.

    Property Access:

    • Instance: This property can be accessed via an instance object of this class:
      • myObject.model_name
    partition
    : STRING

    Returns model’s Db partition.

    Possible Values (STRING):

    local

    This partition is used automatically if the model is not a sync model.

    user

    This partition is used automatically if the model is a sync model.

    app

    This partition is used to store the application related information.

    Property Access:

    • Instance: This property can be accessed via an instance object of this class:
      • myObject.partition
    source_id
    : INTEGER

    Returns model’s source_id.

    Property Access:

    • Instance: This property can be accessed via an instance object of this class:
      • myObject.source_id
    sync_priority
    : INTEGER

    This number determines the order in which the models are processed and synchronised. Priority starts from lower value 1. Lower the number, higher is the priority. Default value is 1000.

    Property Access:

    • Instance: This property can be accessed via an instance object of this class:
      • myObject.sync_priority
    sync_type
    : STRING

    Returns model’s Sync type.

    Default: none

    Possible Values (STRING):

    none

    If data model is not a sync model.

    incremental

    Used when the data model is a sync model. Just syncs changes.

    bulk_only

    If the model is used only for bulk sync.

    Property Access:

    • Instance: This property can be accessed via an instance object of this class:
      • myObject.sync_type

    Examples

    find_by_sql

    Finds the objects of a specific model using the SQL query statements.

    var stdobjData = stdObj.find_by_sql("SELECT * FROM Student WHERE department = 'Mechanical'");  
                                
    result = stdObj.find_by_sql("SELECT * FROM Student WHERE department = 'Electronics'")  
                                
    create

    To create a model’s object including initialization.

    var accounts = Account.create({"name":"Craig", "age":"20"}); 
                                
    accounts = Account.create({"name"=>"Craig","age"=>"20"}) 
                                
    setSchemaIndex

    To set an index name to a set of attributes and indicating whether it is unique or not.

    model.setSchemaIndex("p1", ["name","price"], false); 
                                
    model.setSchemaIndex("p1", ["name","price"], false)          
                                
    setBelongsTo

    Using this method, you can set sync association between models.

    var prdobjData = model.setBelongsTo("itemName", "Product");
                                
    prdobjData = model.setBelongsTo("itemName", "Product") 
                                
    paginate Method Examples

    To fetch the first 10 records.

    var accounts = Account.paginate({page:0});  
                                
    accounts = Account.paginate({:page=>0})  
                                

    To fetch the records numbered 21-40.

    var accounts = Account.paginate({page:1,per_page:20});  
                                
    accounts = Account.paginate({:page=>1,:per_page=>20})  
                                

    To fetch the records based on some conditions and ordering them as well.

    var accounts = Account.paginate({ page:5,
                        conditions:{'name':'Fred','salary':4000},
                        order: 'salary'
                        });  
                                
    accounts = Account.paginate({ :page=>5,
                        :conditions=>{'name'=>'Fred','salary'=>4000},
                        :order=> 'salary'
                        })  
                                
    save

    Saves the current model object to the database.

    var account = Account.make({"name": "Symbol", "industry": "electronics"});
                    account.save(); 
                                        
    account = Account.make({"name"=>"Symbol", "industry"=>"electronics"});
                    account.save() 
                                        
    update_attributes

    Updates the current model object’s attributes and saves it to the database.

    var account = Account.create({'name': 'Symbol', 'industry': 'electronics'});
                account.update_attributes({'name':'ABB','industry':'robotics'});
                account.get("industry"); //"robotics"   
                                        
    account = Account.create({'name'=> 'Symbol', 'industry'=> 'electronics'})
                account.update_attributes({'name'=>'ABB','industry'=>'robotics'})
                account.get("industry") //"robotics"    
                                        
    destroy

    Destroy a model object from database.

    var account = Account.find('first');
                account.destroy(); 
                                
    account = Account.find(:first)
                account.destroy() 
                                
    has

    Checks whether the propertyName exists in the model.

    var account = Account.find('first');
                account.has('salary'); 
                                
    account = Account.find(:first)
                account.has('salary') 
                                
    vars

    Returns all the propertyNames and it’s values for the model.

    var accounts = Account.create({"name":"Craig", "age":20});
                account.vars(); 
                                
    accounts = Account.create({"name"=>"Craig", "age"=>20})
                account.vars()