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. |
Checks whether the model has any changed objects.
Synchronous Return:
Method Access:
myObject.anyChangedObjects()
Checks whether the object can be modified.
Parameters
Synchronous Return:
Method Access:
myObject.canModify(STRING objId)
Checks whether the object can be modified.
Parameters
Synchronous Return:
Method Access:
myObject.can_modify(STRING objId)
Returns true if a Rhodes model object has local database changes that need to be synchronized, false otherwise.
Synchronous Return:
Method Access:
myObject.changed?()
Returns the current sync client id.
Synchronous Return:
Method Access:
myObject.client_id()
Returns the number of objects in the named model.
Synchronous Return:
Method Access:
myObject.count()
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
List of attributes assigned to the new model object, such as {name : “ABC Inc.”,address: “555 5th St.”}.
Synchronous Return:
Method Access:
myObject.create(HASH attrs)
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
A hash-map with deleteAll arguments.
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:
Method Access:
myObject.deleteAll(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
A hash-map with deleteAll arguments.
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:
Method Access:
myObject.delete_all(HASH params)
Sets model’s Boolean property to true (enables model’s property)
Parameters
Possible Values :
To set the type of model as Fixed_schema.
To make the model as user model.
To send all the attributes(changed/unchanged) to Rhoconnect when an object is updated.
To keep the sensitive data out of redis server.
Synchronous Return:
Method Access:
myObject.enable(STRING propertyName)
Find model objects.
Parameters
Possible Values :
returns all objects; can use optional :conditions.
returns first object matching :conditions.
returns the number of objects matching these :conditions.
An object of selection options
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”]).
Attribute(s) to order the list.
Order direction.
Possible Values :
Ascending order. (Default)
Descending Order
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:
Method Access:
myObject.find(STRING queryType, HASH queryOptions)
find(‘all’) replaces the legacy ruby method find_all.
Synchronous Return:
Method Access:
myObject.find_all()
Returns array of objects for the given model queried according to the specified SQL.
Parameters
Synchronous Return:
Method Access:
myObject.find_by_sql(STRING sqlQuery)
Get the value of a property of the current model.Ex: myModel.get(‘name’); See also the vars() method.
Parameters
The name of the property you are trying to retrieve.
Synchronous Return:
Value of the specified property from the database.
Method Access:
myObject.get(STRING propertyName)
This method will return all of object/value pairs for the propertyNames of the API class.
Parameters
Async Callback Returning Parameters: HASH
Synchronous Return:
Map of all available properties
: this method also supports async callbacks - check the Callback tab for callback return parameters.
Method Access:
myObject.getAllProperties(CallBackHandler callback)
Returns time string when the source has been synced.
Synchronous Return:
Method Access:
myObject.getBackendRefreshTime()
Returns info about model’s relationships with other models.
Parameters
Synchronous Return:
Method Access:
myObject.getBelongsTo(STRING propertyName)
Returns total number of objects for the model.
Synchronous Return:
Method Access:
myObject.getCount()
getModel method returns instance of the ORMModel.
Parameters
Name of the model you want returned.
Synchronous Return:
NewORMModel object.
Method Access:
Rho.NewORMModel.getModel(STRING modelName)
Rho::NewORMModel.getModel(STRING modelName)
Returns info about model’s field property.
Parameters
The name of the property.
Synchronous Return:
Returns property name,type and option in the form of an HASH.
Method Access:
myObject.getModelProperty(STRING propertyName)
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
List of properties I want to know about
Async Callback Returning Parameters: HASH
Synchronous Return:
Map of properties I want to know about
: this method also supports async callbacks - check the Callback tab for callback return parameters.
Method Access:
myObject.getProperties(ARRAY arrayofNames, 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
The property to return info about.
Async Callback Returning Parameters: STRING
Synchronous Return:
The property to return info about.
: this method also supports async callbacks - check the Callback tab for callback return parameters.Method Access:
myObject.getProperty(STRING propertyName, CallBackHandler callback)
Returns the source id number for this Rhodes model object. Please use the model property source_id.
Synchronous Return:
Method Access:
myObject.get_source_id()
Returns the source name for this Rhodes model object. Please use the model property model_name.
Synchronous Return:
Method Access:
myObject.get_source_name()
Returns true if the model has the propertyName given.
Parameters
The name of the property you are checking for its existence.
Synchronous Return:
Method Access:
myObject.has(STRING propertyName)
Checks whether the object has any changes. Returns true when an object is created or updated.
Parameters
Synchronous Return:
Method Access:
myObject.hasChanges(STRING objId)
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:
Method Access:
myObject.make()
Initializes new model’s instance.
Parameters
Synchronous Return:
Method Access:
myObject.new(STRING modelName)
Handles sync create errors.
Parameters
Synchronous Return:
Method Access:
myObject.onSyncCreateError(ARRAY objects, STRING action)
Handles sync delete errors for the object.
Parameters
Synchronous Return:
Method Access:
myObject.onSyncDeleteError(STRING objId, HASH attrHash, STRING action)
Handles sync update errors for the object.
Parameters
Synchronous Return:
Method Access:
myObject.onSyncUpdateError(STRING objId, HASH attrHash, HASH rollbackHash, STRING action)
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
A hash-map with paginate arguments.
This value is an offset which indicates the prevailing page number.
This value specifies number of records to be returned. The default value of per_page is 10.
hash of attribute/values. Also supports sql fragment with binding(i.e. [“name=?”, “company_name”]).
The attribute names to order the list.
Order direction: ‘ASC’ ascending, ‘DESC’ descending. Default = ‘ASC’.
The array of string attributes to return with the object.
Synchronous Return:
Method Access:
myObject.paginate(HASH params)
Pushes all changes for the source. For details push_changes
Synchronous Return:
Method Access:
myObject.pushChanges()
Pushes all changes for the source.
Synchronous Return:
Method Access:
myObject.push_changes()
Saves the object’s attributes in the DB.
Synchronous Return:
Method Access:
myObject.save()
Sets model’s property to value with additional processing for :sync property.
Parameters
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 :
This partition is used automatically if the model is not a sync model.
This partition is used automatically if the model is a sync model.
This partition is used to store the application related information.
Sets the type of sync it will be.
Possible Values :
If data model is not a sync model.
Used when the data model is a sync model. Just syncs changes.
If the model is used only for bulk sync.
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.
To make the model Freezed.
This is used for data migration of the application.
The property names takes the corresponding property values, as mentioned above .
Synchronous Return:
Method Access:
myObject.set(STRING propertyName, STRING propertyValue)
Using this method, you can set sync association between models. For details Associations
Parameters
Synchronous Return:
Method Access:
myObject.setBelongsTo(STRING propertyName, STRING sourceName)
Initializes new model’s field property.
Parameters
The name of the property.
The type of property. Possible values are: String, Float, integer, Boolean, Varchar, Blob. String is default.
Possible Values :
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:
Method Access:
myObject.setModelProperty(STRING propertyName, STRING propertyType, STRING propOption)
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
Map of properties I want to set
Synchronous Return:
Method Access:
myObject.setProperties(HASH propertyMap)
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
The one property name that I want to set
The one property value that I want to set
Synchronous Return:
Method Access:
myObject.setProperty(STRING propertyName, STRING propertyValue)
Initializes new model’s schema index.
Parameters
To define a named index on a set of attributes.
A set of attributes which need a indexName are passed through this array.
To make the indexCols as unique column is_unique is set to true. This will prevent inserting duplicate records.
Synchronous Return:
Method Access:
myObject.setSchemaIndex(STRING indexName, ARRAY indexCols, BOOLEAN is_unique)
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
List of attributes and their updated values are passed as a key-value pair in this HASH.
Synchronous Return:
Method Access:
myObject.updateAttributes(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
List of attributes and their updated values are passed as a key-value pair in this HASH.
Synchronous Return:
Method Access:
myObject.update_attributes(HASH attributes)
Returns an object containing all propertyName and values for the model. You can use myModel.vars().name instead of myModel.get(‘name’).
Synchronous Return:
Method Access:
myObject.vars()
Returns model’s associations.
Property Access:
myObject.associations
Returns true if the model’s type is of fixed schema.
Property Access:
myObject.fixed_schema
Returns true if the model is frozen.
Property Access:
myObject.freezed
Returns true if model is loaded.
Property Access:
myObject.loaded
Returns model’s name.
Property Access:
myObject.model_name
Returns model’s Db partition.
Possible Values (STRING):
This partition is used automatically if the model is not a sync model.
This partition is used automatically if the model is a sync model.
This partition is used to store the application related information.
Property Access:
myObject.partition
Returns model’s source_id.
Property Access:
myObject.source_id
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:
myObject.sync_priority
Returns model’s Sync type.
Default: none
Possible Values (STRING):
If data model is not a sync model.
Used when the data model is a sync model. Just syncs changes.
If the model is used only for bulk sync.
Property Access:
myObject.sync_type
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'")
To create a model’s object including initialization.
var accounts = Account.create({"name":"Craig", "age":"20"});
accounts = Account.create({"name"=>"Craig","age"=>"20"})
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)
Using this method, you can set sync association between models.
var prdobjData = model.setBelongsTo("itemName", "Product");
prdobjData = model.setBelongsTo("itemName", "Product")
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' })
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()
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 a model object from database.
var account = Account.find('first'); account.destroy();
account = Account.find(:first) account.destroy()
Checks whether the propertyName exists in the model.
var account = Account.find('first'); account.has('salary');
account = Account.find(:first) account.has('salary')
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()