<commit_before><?xml version = "1.0"?>
<?xml-stylesheet type="text/xsl" href="pb_help.xsl"?>
<API>
  <MODULE name="ORMModel" parent="Rho">
    <HELP_OVERVIEW>The ORM Model provides CRUD and helper methods for your defined model to interact with the database.  You must define and add a model before you can use the ORM Model Object.  See Orm to learn about defining and adding a model.
    </HELP_OVERVIEW>
    <LINK><a href='./Orm'>Orm</a></LINK> 
    <MORE_HELP> See remarks for different between ruby and javascript usage.
    </MORE_HELP>


    <TEMPLATES>
    </TEMPLATES>

    <PROPERTIES>
      <PROPERTY name="metadata" access="STATIC" type="HASH" generateAPI="false">
        <DESC>Ruby only. Returns the metadata definition for a given model as a hash.
          Assigns the hash metadata definition for a given model.
        </DESC>
      </PROPERTY>
    </PROPERTIES>

    <METHODS>
      <ALIASES>
        <ALIAS new="changed?" existing="isChanged"></ALIAS>
      </ALIASES>
      <METHOD name="clearNotification" deprecated="true" generateAPI="false" access="STATIC">
        <DESC>Clear notification for the object. Use Rhoconnect-client</DESC>
      </METHOD>
      <METHOD name="deleteAll" generateAPI="false" access="STATIC">
        <DESC>Delete all Rhodes model objects for a source.
          example.
        </DESC>
        <PARAMS>
          <PARAM name="conditions" type="HASH">
            <DESC>Ruby only. Hash of attribute/values; delete only objects matching these criteria, such as :conditions =>
              {'industry'=>'electronics'}.
            </DESC>
            <CAN_BE_NIL/>
          </PARAM>
          <PARAM name="op" type="STRING">
            <DESC>Ruby only. operator, such as "OR" or "IN". Allows you to have more than one set of conditions.</DESC>
            <CAN_BE_NIL/>
          </PARAM>
        </PARAMS>
      </METHOD>
      <METHOD name="find" generateAPI="false" access="STATIC">
        <DESC>Find model objects.
        </DESC>
        <PARAMS>
          <PARAM name="queryType" type="STRING">
            <VALUES>
              <VALUE value="all" type="STRING">
                <DESC>returns all objects; can use optional :conditions.</DESC>
              </VALUE>
              <VALUE value="first" type="STRING">
                <DESC>returns first object matching :conditions.</DESC>
              </VALUE>
              <VALUE value="count" type="STRING">
                <DESC>returns the number of objects matching these :conditions.</DESC>
              </VALUE>
            </VALUES>
          </PARAM>
          <PARAM name="conditions" type="HASH">
            <DESC>Hash of attribute/values. Also supports sql fragments (i.e. "name like 'Ormobile'") or sql fragment
              with binding (you have to define :select with sql queries) (i.e. ["name like ?", "'#{company#}'"]) Use a
              comma around string values.
            </DESC>
            <CAN_BE_NIL/>
          </PARAM>
          <PARAM name="order" type="STRING">
            <DESC>Attribute(s) to order the list.</DESC>
            <CAN_BE_NIL/>
          </PARAM>

          <PARAM name="orderdir" type="STRING">
            <DESC>Order direction: 'ASC' ascending, 'DESC' descending. Default = 'ASC'.)</DESC>
            <CAN_BE_NIL/>
          </PARAM>

          <PARAM name="select" type="ARRAY">
            <DESC>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.
            </DESC>
            <CAN_BE_NIL/>
          </PARAM>

          <PARAM name="perPage" type="INTEGER">
            <DESC>Ruby only. Maximum number of items to return.</DESC>
            <CAN_BE_NIL/>
          </PARAM>

          <PARAM name="offset" type="INTEGER">
            <DESC>Ruby only. Offset from beginning of the list.</DESC>
            <CAN_BE_NIL/>
          </PARAM>

          <PARAM name="op" type="STRING">
            <DESC>Ruby only. Operator, such as "OR" or "IN". Allows you to have more than one set of conditions.</DESC>
            <CAN_BE_NIL/>
          </PARAM>
        </PARAMS>
        <RETURN type="ARRAY"/>
      </METHOD>
      <METHOD name="findAll" generateAPI="false" access="STATIC">
        <DESC>Ruby only. Alias for modelname.find(:all, argument list).</DESC>
        <RETURN type="ARRAY"/>
      </METHOD>
      <METHOD name="findBySql" generateAPI="false" access="STATIC">
        <DESC>Ruby only. Returns Rhodes model object(s) based on sql_query. This method works only for schema models.
        </DESC>
        <PARAMS>
          <PARAM name="query" type="STRING">
            <DESC>An sql query, such as "SELECT * FROM Account".</DESC>
          </PARAM>
        </PARAMS>
        <RETURN type="ARRAY"/>
      </METHOD>
      <METHOD name="getSourceName" generateAPI="false" access="STATIC">
        <DESC>Ruby only. Returns the source name for this Rhodes model object.</DESC>
        <RETURN type="STRING"/>
      </METHOD>
      <METHOD name="new" generateAPI="false" access="STATIC">
        <DESC>Ruby only. Create a new Rhodes model object. Orm new example.</DESC>
        <PARAMS>
          <PARAM name="attributes" type="HASH">
            <DESC>List of attributes assigned to the new model object, such as {"name" => "ABC Inc.","address" => "555
              5th St."}.
            </DESC>
          </PARAM>
        </PARAMS>
        <RETURN type="OBJECT"/>
      </METHOD>
      <METHOD name="make" generateAPI="false" access="STATIC">
        <DESC>Javascript only. Create a new Rhodes model object. Orm new example.</DESC>
        <PARAMS>
          <PARAM name="attributes" type="HASH">
            <DESC>List of attributes assigned to the new model object, such as {"name" => "ABC Inc.","address" => "555
              5th St."}.
            </DESC>
          </PARAM>
        </PARAMS>
        <RETURN type="OBJECT"/>
      </METHOD>
      <METHOD name="create" generateAPI="false" access="STATIC">
        <DESC>Create a new Rhodes model object and save it to the database.Orm create example. This is the fastest way
          to insert a single item into the database.
        </DESC>
        <PARAMS>
          <PARAM name="attributes" type="HASH">
            <DESC>List of attributes assigned to the new model object, such as {"name" => "ABC Inc.","address" => "555
              5th St."}.
            </DESC>
          </PARAM>
        </PARAMS>
        <RETURN type="OBJECT"/>
      </METHOD>
      <METHOD name="paginate" generateAPI="false" access="STATIC">
        <DESC>Ruby only. Call find with a limit on the number of records. Default page size is 10. Orm paginate example.</DESC>
        <PARAMS>
          <PARAM name="page" type="INTEGER">
            <DESC>which page to return.</DESC>
          </PARAM>

          <PARAM name="perPage" type="INTEGER">
            <DESC>with :page (used as offset), the number of records to return, such as :page => 1, :per_page => 20
            </DESC>
          </PARAM>

          <PARAM name="conditions" type="HASH">
            <DESC>same as find with :conditions</DESC>
          </PARAM>

          <PARAM name="order" type="STRING">
            <DESC>same as find with :conditions</DESC>
          </PARAM>

          <PARAM name="select" type="ARRAY">
            <DESC>same as find with :select</DESC>
          </PARAM>

        </PARAMS>
        <RETURN type="ARRAY"/>
      </METHOD>
      <METHOD name="sync" generateAPI="false" access="STATIC">
        <DESC>Start the sync process for a Rhodes model.</DESC>
        <PARAMS>
          <PARAM name="callbackUrl" type="STRING">
            <DESC>the url for the sync callback method. If this is used, SyncEngine.set_notification is called before
              SyncEngine.dosync.
            </DESC>
          </PARAM>

          <PARAM name="callbackData" type="STRING">
            <DESC>Data for the callback method.</DESC>
          </PARAM>

          <PARAM name="showStatusPopup" type="BOOLEAN">
            <DESC>true if you want to show a popup window upon sync, false otherwise.</DESC>
            <CAN_BE_NIL/>
          </PARAM>

          <PARAM name="queryParams" type="STRING">
            <DESC>query to pass to the sync server. The query_params value must be URL encoded.</DESC>
            <CAN_BE_NIL/>
          </PARAM>
        </PARAMS>
      </METHOD>
      <METHOD name="isChanged" generateAPI="false" access="STATIC">
        <DESC>Ruby only. Returns true if a Rhodes model object has local database changes that need to be synchronized, false
          otherwise.
        </DESC>
        <RETURN type="BOOLEAN"/>
      </METHOD>
      <METHOD name="haveLocalChanges" generateAPI="false" access="STATIC">
        <DESC>Javascript only. Returns true if a Rhodes model object has local database changes that need to be synchronized, false
          otherwise.
        </DESC>
        <RETURN type="BOOLEAN"/>
      </METHOD>
      <METHOD name="setNotification" hasCallback="mandatory" deprecated="true" runInThread="none" generateAPI="false" access="STATIC">
        <DESC>Use Rhoconect-Client. Saves the current Rhodes model object to the database.
        </DESC>
        <PARAMS>

          <PARAM name="callbackUrl" type="STRING">
            <DESC>the url for your sync is finished notification callback method.
            </DESC>
          </PARAM>

          <PARAM name="params" type="STRING">
            <DESC>parameters for the callback method.</DESC>
            <CAN_BE_NIL/>
          </PARAM>
        </PARAMS>

      </METHOD>

      <METHOD name="destroy" generateAPI="false">
        <DESC>Destroy a Rhodes model object.</DESC>
      </METHOD>
      <METHOD name="canModify" deprecated="true" generateAPI="false">
        <DESC>Returns true if the Rhodes model object is not currently being synced (if it is being synced, you should
          disable editing of the object). 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.
        </DESC>
        <RETURN type="BOOLEAN"/>
      </METHOD>
      <METHOD name="save" generateAPI="false">
        <DESC>Saves the current Rhodes model object to the database.
        </DESC>
      </METHOD>
      <METHOD name="updateAttributes" generateAPI="false">
        <DESC>Updates the current Rho model object attributes and saves it to the database. This is the fastest way to
          add or update model attributes.
        </DESC>
        <PARAMS>
          <PARAM name="attributes" type="HASH">
            <DESC>List of attributes and their updated values, such as {"name" => "<NAME>.","address" => "555 5th
              St."}.
            </DESC>
          </PARAM>
        </PARAMS>
      </METHOD>

    </METHODS>

    <USER_OVERVIEW>
      <!--  More conversational style with INLINE SAMPLES, written in MarkDown -->
      <![CDATA[]]>

    </USER_OVERVIEW>
    <VER_INTRODUCED>1.0.0</VER_INTRODUCED>
    <PLATFORM>
      <!--  This section is used for the supported platform images at the top -->
    </PLATFORM>
    <EXAMPLES>
      <EXAMPLE title="ORM DeleteAll Method Examples">
        <SECTIONS>
          <SECTION>
            <DESC>
              Delete all Rhodes model objects for a source, filtering by conditions.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
Account.deleteAll(:conditions => {'industry'=>'electronics', 'website'=>'electronics.com'})]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[
Account.deleteAll();]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>

        </SECTIONS>
      </EXAMPLE>
      <EXAMPLE title="ORM Find Method Examples">
        <SECTIONS>

          <SECTION>
            <DESC>
              Find all objects for specific ORM model
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
accounts = Account.find(:all)]]>
              </RUBY>
              <JAVASCRIPT>

                <![CDATA[
vat accounts = Account.find('all');]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>

          <SECTION>
            <DESC>
              Find all objects for specific ORM model with conditions
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
Account.find(:all, :conditions => {'industry' => 'Technology'}) ]]>
              </RUBY>
              <JAVASCRIPT>

                <![CDATA[
var accounts = Account.find(
    'all',
    {
      conditions: {industry: 'Technology'}
    }
  ) ]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>

          <SECTION>
            <DESC>
              Use select option for retrieves some attributes of object.  You must pass "conditions" hash with Javascript implementation.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
accounts = Account.find(:all, :select => ['name','address'])
accounts[0].name
  #=> "<NAME> PLC 37862"
accounts[0].telephone
  #=> nil ]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[
var accounts = Account.find(
    'all',
    {
      conditions: {name:'address'},
      select: ['name','address']
    }
  );
accounts[0].get("name");  // "<NAME> PLC 37862"
accounts[0].get("telephone"); // nil ]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>

          <SECTION>
            <DESC>
              Order option is used to sort objects by one or more attributes.
              The order argument for find accepts several fORMs.


              Order by one attribute. Javascript must pass conditions hash.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
accounts = Account.find(
      :all,
      :order => 'name',
      :orderdir => 'DESC'
    ) ]]>
              </RUBY>
              <JAVASCRIPT>

                <![CDATA[
var accounts = Account.find(
    'all',
    {
      conditions: {"name":"industry"},
      order: 'name',
      orderdir: 'DESC'
    }
  ) ]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>

          <SECTION>
            <DESC>
              Order by multiple attributes. Javascript must pass conditions hash.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
accounts = Account.find(
      :all,
      :order => ['name', 'industry'],
      :orderdir => ['ASC', 'DESC']
    ) ]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[
var accounts = Account.find(
    'all',
    {
      conditions: {"name":"industry"},
      order: ['name', 'industry'],
      orderdir: ['ASC', 'DESC']
    }
  ); ]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>

          <SECTION>
            <DESC>
              Order by one attribute with a block.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
accounts = Account.find(:all, :order => 'name') do |x,y|
      y <=> x
    end ]]>
              </RUBY>
              <JAVASCRIPT>

                <![CDATA[
var accounts = Account.find(
    'all',
    {
      order: 'name',
      orderFunction: function (a, b) { return a <= b }
    }
  ); ]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>
          <SECTION>
            <DESC>
              Order with a block.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
accounts = Account.find(:all) do |item1,item2|
      item2.name <=> item1.name
    end ]]>
              </RUBY>
              <JAVASCRIPT>

                <![CDATA[
var accounts = Account.find(
    'all',
    {
      orderFunction: function (item1, item2) { return item1.name <= item2.name }
    }
  ); ]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>


        </SECTIONS>
      </EXAMPLE>
      <EXAMPLE title="ORM New and Create Method Examples">
        <SECTIONS>
          <SECTION>
            <DESC>
              Use method New for creating a new ORM object and assign given attributes.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
account = Account.new({"name" => "ABC Inc.", "address" => "555 5th St."})
account.name
  #=> "ABC Inc." ]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[
var account = Account.make({name: "ABC Inc.", address: "555 5th St."});
account.get("name") // "ABC Inc." ]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>
          <SECTION>
            <DESC>
              Use method Create for creating a new ORM object and save to the database.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
account = Account.create({"name" => "some new record", "industry" => "electronics"}) ]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[
var account = Account.create({name: "<NAME>", industry: "electronics"})  ]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>
        </SECTIONS>
      </EXAMPLE>
      <EXAMPLE title="ORM Paginate Method Example">
        <SECTIONS>
          <SECTION>
            <DESC>
              Paginate calls find with a limit on the # of records. This emulates rails' classic pagination syntax.
              Default page size is 10.


              Retrieve first 10 records:
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
Account.paginate(:page => 0) ]]>
              </RUBY>
            </CODE>
          </SECTION>

          <SECTION>
            <DESC>
              Retrieve records 21-40
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
Account.paginate(:page => 1, :perPage => 20) ]]>
              </RUBY>
            </CODE>
          </SECTION>

          <SECTION>
            <DESC>
              You can have conditions and order as well
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
Account.paginate(
  :page => 5,
  :conditions => {'industry' => 'Technology'},
  :order => 'name'
) ]]>
              </RUBY>
            </CODE>
          </SECTION>

        </SECTIONS>
      </EXAMPLE>
      <EXAMPLE title="ORM Sync and setNotification Method Example">
        <SECTIONS>
          <SECTION>
            <DESC>
              Start the sync process for a model. In this example, the value for @params[“sku”] — the value of the sku —
              must be URL encoded.
            </DESC>
            <CODE lang="ruby">
              <RUBY>
                <![CDATA[
Product.sync( url_for(:action => :sync_callback), "", false, "query=#{@params["sku"]}" ) ]]>
              </RUBY>
            </CODE>
          </SECTION>

          <SECTION>
            <DESC>
              Set a notification to be called when the sync is complete for this model. This is useful for example if
              you want to refresh the current list page or display an alert when new data is synchronized. See the sync
              notification docs for more infORMation.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
              Account.setNotification( url_for(:action => :sync_notify) ) ]]>
              </RUBY>
            </CODE>
          </SECTION>

        </SECTIONS>
      </EXAMPLE>
      <EXAMPLE title="ORM IsChanged Method Example">
        <SECTIONS>
          <SECTION>
            <DESC>
              Determine if a ORM model has local database changes that need to be synchronized.  Must enable sync to use this function.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
                def should_sync_product_object
  if Product.isChanged
    #... do stuff ...
  end
end  ]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[

  if (Product.haveLocalChanges()) {
      //... do stuff ...
    }
  ]]>
              </JAVASCRIPT>
            </CODE>
          </SECTION>
        </SECTIONS>
      </EXAMPLE>

      <EXAMPLE title="ORM Destroy Method Examples">
        <SECTIONS>
          <SECTION>
            <DESC>
              Destroy a Rhodes model object.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
@account = Account.find(:first)
@account.destroy]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[
var account = Account.find('first');
account.destroy();]]>
              </JAVASCRIPT>

            </CODE>

          </SECTION>
        </SECTIONS>
      </EXAMPLE>
      <EXAMPLE title="ORM UpdateAttributes Method Example">
        <SECTIONS>
          <SECTION>
            <DESC>Update the current ORM object’s attributes and saves it to the database.</DESC>
            <CODE>
              <RUBY>
                <![CDATA[
account = Account.find(
  :first,
  :conditions => {'name' => '<NAME>.'}
)
account.update_attributes({"name" => "<NAME>.", "industry" => "Technology"})

account.industry
  #=> "Technology" ]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[
var account = Account.find("first", {conditions: {name: "<NAME>."});
account.updateAttributes({name: "<NAME>.", industry: "Technology"});
account.get("industry") // "Technology" ]]>
              </JAVASCRIPT>
            </CODE>
          </SECTION>
        </SECTIONS>
      </EXAMPLE>
      <EXAMPLE title="ORM Save Method Example">
        <SECTIONS>
          <SECTION>
            <DESC>Saves the current ORM object to the database.</DESC>
            <CODE>
              <RUBY>
                <![CDATA[
account = Account.new({"name" => "<NAME>", "industry" => "electronics"})
account.save ]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[
var account = Account.make({name: "<NAME>", industry: "electronics"});
account.save(); ]]>
              </JAVASCRIPT>
            </CODE>
          </SECTION>

        </SECTIONS>
      </EXAMPLE>
      <EXAMPLE title="ORM CanModify Method Example">
        <SECTIONS>
          <SECTION>
            <DESC>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. canModify 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.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
def edit
  @product = Product.find(@params['id'])
  if @product && !@product.canModify
    render :action => :show_edit_error
  else
    render :action => :edit
  end
end  ]]>
              </RUBY>
            </CODE>
          </SECTION>
        </SECTIONS>
      </EXAMPLE>
    </EXAMPLES>
  </MODULE>
</API>
<commit_msg>use applies tag for ruby-only and js-only methods/properties<commit_after><?xml version = "1.0"?>
<?xml-stylesheet type="text/xsl" href="pb_help.xsl"?>
<API>
  <MODULE name="ORMModel" parent="Rho">
    <HELP_OVERVIEW>The ORM Model provides CRUD and helper methods for your defined model to interact with the database.  You must define and add a model before you can use the ORM Model Object.  See Orm to learn about defining and adding a model.
    </HELP_OVERVIEW>
    <LINK><a href='./Orm'>Orm</a></LINK> 
    <MORE_HELP> See remarks for different between ruby and javascript usage.
    </MORE_HELP>


    <TEMPLATES>
    </TEMPLATES>

    <PROPERTIES>
      <PROPERTY name="metadata" access="STATIC" type="HASH" generateAPI="false">
        <DESC>Returns the metadata definition for a given model as a hash.
          Assigns the hash metadata definition for a given model.
        </DESC>
        <APPLIES rubyOnly="true"/>
      </PROPERTY>
    </PROPERTIES>

    <METHODS>
      <ALIASES>
        <ALIAS new="changed?" existing="isChanged"></ALIAS>
      </ALIASES>
      <METHOD name="clearNotification" deprecated="true" generateAPI="false" access="STATIC">
        <DESC>Clear notification for the object. Use Rhoconnect-client</DESC>
      </METHOD>
      <METHOD name="deleteAll" generateAPI="false" access="STATIC">
        <DESC>Delete all Rhodes model objects for a source.
          example.
        </DESC>
        <PARAMS>
          <PARAM name="conditions" type="HASH">
            <DESC>Hash of attribute/values; delete only objects matching these criteria, such as :conditions =>
              {'industry'=>'electronics'}.
            </DESC>
            <CAN_BE_NIL/>
            <APPLIES rubyOnly="true"/>
          </PARAM>
          <PARAM name="op" type="STRING">
            <DESC>Operator, such as "OR" or "IN". Allows you to have more than one set of conditions.</DESC>
            <CAN_BE_NIL/>
            <APPLIES rubyOnly="true"/>
          </PARAM>
        </PARAMS>
      </METHOD>
      <METHOD name="find" generateAPI="false" access="STATIC">
        <DESC>Find model objects.
        </DESC>
        <PARAMS>
          <PARAM name="queryType" type="STRING">
            <VALUES>
              <VALUE value="all" type="STRING">
                <DESC>returns all objects; can use optional :conditions.</DESC>
              </VALUE>
              <VALUE value="first" type="STRING">
                <DESC>returns first object matching :conditions.</DESC>
              </VALUE>
              <VALUE value="count" type="STRING">
                <DESC>returns the number of objects matching these :conditions.</DESC>
              </VALUE>
            </VALUES>
          </PARAM>
          <PARAM name="conditions" type="HASH">
            <DESC>Hash of attribute/values. Also supports sql fragments (i.e. "name like 'Ormobile'") or sql fragment
              with binding (you have to define :select with sql queries) (i.e. ["name like ?", "'#{company#}'"]) Use a
              comma around string values.
            </DESC>
            <CAN_BE_NIL/>
          </PARAM>
          <PARAM name="order" type="STRING">
            <DESC>Attribute(s) to order the list.</DESC>
            <CAN_BE_NIL/>
          </PARAM>

          <PARAM name="orderdir" type="STRING">
            <DESC>Order direction: 'ASC' ascending, 'DESC' descending. Default = 'ASC'.)</DESC>
            <CAN_BE_NIL/>
          </PARAM>

          <PARAM name="select" type="ARRAY">
            <DESC>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.
            </DESC>
            <CAN_BE_NIL/>
          </PARAM>

          <PARAM name="perPage" type="INTEGER">
            <DESC>Maximum number of items to return.</DESC>
            <CAN_BE_NIL/>
            <APPLIES rubyOnly="true"/>
          </PARAM>

          <PARAM name="offset" type="INTEGER">
            <DESC>Offset from beginning of the list.</DESC>
            <CAN_BE_NIL/>
            <APPLIES rubyOnly="true"/>
          </PARAM>

          <PARAM name="op" type="STRING">
            <DESC>Operator, such as "OR" or "IN". Allows you to have more than one set of conditions.</DESC>
            <CAN_BE_NIL/>
            <APPLIES rubyOnly="true"/>
          </PARAM>
        </PARAMS>
        <RETURN type="ARRAY"/>
      </METHOD>
      <METHOD name="findAll" generateAPI="false" access="STATIC">
        <DESC>Alias for Model.find(:all, argument list).</DESC>
        <RETURN type="ARRAY"/>
        <APPLIES rubyOnly="true"/>
      </METHOD>
      <METHOD name="findBySql" generateAPI="false" access="STATIC">
        <DESC>Returns Rhodes model object(s) based on sql_query. This method works only for schema models.
        </DESC>
        <PARAMS>
          <PARAM name="query" type="STRING">
            <DESC>An sql query, such as "SELECT * FROM Account".</DESC>
          </PARAM>
        </PARAMS>
        <RETURN type="ARRAY"/>
        <APPLIES rubyOnly="true"/>
      </METHOD>
      <METHOD name="getSourceName" generateAPI="false" access="STATIC">
        <DESC>Returns the source name for this Rhodes model object.</DESC>
        <RETURN type="STRING"/>
        <APPLIES rubyOnly="true"/>
      </METHOD>
      <METHOD name="new" generateAPI="false" access="STATIC">
        <DESC>Create a new Rhodes model object. Orm new example.</DESC>
        <PARAMS>
          <PARAM name="attributes" type="HASH">
            <DESC>List of attributes assigned to the new model object, such as {"name" => "ABC Inc.","address" => "555
              5th St."}.
            </DESC>
          </PARAM>
        </PARAMS>
        <RETURN type="OBJECT"/>
        <APPLIES rubyOnly="true"/>
      </METHOD>
      <METHOD name="make" generateAPI="false" access="STATIC">
        <DESC>Create a new Rhodes model object. Orm new example.</DESC>
        <PARAMS>
          <PARAM name="attributes" type="HASH">
            <DESC>List of attributes assigned to the new model object, such as {"name" => "ABC Inc.","address" => "555
              5th St."}.
            </DESC>
          </PARAM>
        </PARAMS>
        <RETURN type="OBJECT"/>
        <APPLIES jsOnly="true"/>
      </METHOD>
      <METHOD name="create" generateAPI="false" access="STATIC">
        <DESC>Create a new Rhodes model object and save it to the database.Orm create example. This is the fastest way
          to insert a single item into the database.
        </DESC>
        <PARAMS>
          <PARAM name="attributes" type="HASH">
            <DESC>List of attributes assigned to the new model object, such as {"name" => "ABC Inc.","address" => "555
              5th St."}.
            </DESC>
          </PARAM>
        </PARAMS>
        <RETURN type="OBJECT"/>
      </METHOD>
      <METHOD name="paginate" generateAPI="false" access="STATIC">
        <DESC>Call find with a limit on the number of records. Default page size is 10. Orm paginate example.</DESC>
        <PARAMS>
          <PARAM name="page" type="INTEGER">
            <DESC>which page to return.</DESC>
          </PARAM>

          <PARAM name="perPage" type="INTEGER">
            <DESC>with :page (used as offset), the number of records to return, such as :page => 1, :per_page => 20
            </DESC>
          </PARAM>

          <PARAM name="conditions" type="HASH">
            <DESC>same as find with :conditions</DESC>
          </PARAM>

          <PARAM name="order" type="STRING">
            <DESC>same as find with :conditions</DESC>
          </PARAM>

          <PARAM name="select" type="ARRAY">
            <DESC>same as find with :select</DESC>
          </PARAM>

        </PARAMS>
        <RETURN type="ARRAY"/>
        <APPLIES rubyOnly="true"/>
      </METHOD>
      <METHOD name="sync" generateAPI="false" access="STATIC">
        <DESC>Start the sync process for a Rhodes model.</DESC>
        <PARAMS>
          <PARAM name="callbackUrl" type="STRING">
            <DESC>The url for the sync callback method. If this is used, SyncEngine.set_notification is called before
              SyncEngine.dosync.
            </DESC>
          </PARAM>

          <PARAM name="callbackData" type="STRING">
            <DESC>Data for the callback method.</DESC>
          </PARAM>

          <PARAM name="showStatusPopup" type="BOOLEAN">
            <DESC>true if you want to show a popup window upon sync, false otherwise.</DESC>
            <CAN_BE_NIL/>
          </PARAM>

          <PARAM name="queryParams" type="STRING">
            <DESC>query to pass to the sync server. The query_params value must be URL encoded.</DESC>
            <CAN_BE_NIL/>
          </PARAM>
        </PARAMS>
      </METHOD>
      <METHOD name="isChanged" generateAPI="false" access="STATIC">
        <DESC>Returns true if a Rhodes model object has local database changes that need to be synchronized, false
          otherwise.
        </DESC>
        <RETURN type="BOOLEAN"/>
        <APPLIES rubyOnly="true"/>
      </METHOD>
      <METHOD name="haveLocalChanges" generateAPI="false" access="STATIC">
        <DESC>Returns true if a Rhodes model object has local database changes that need to be synchronized, false
          otherwise.
        </DESC>
        <RETURN type="BOOLEAN"/>
        <APPLIES jsOnly="true"/>
      </METHOD>
      <METHOD name="setNotification" hasCallback="mandatory" deprecated="true" runInThread="none" generateAPI="false" access="STATIC">
        <DESC>Use RhoConnectClient.setNotification instead. Saves the current Rhodes model object to the database.
        </DESC>
        <PARAMS>

          <PARAM name="callbackUrl" type="STRING">
            <DESC>the url for your sync is finished notification callback method.
            </DESC>
          </PARAM>

          <PARAM name="params" type="STRING">
            <DESC>parameters for the callback method.</DESC>
            <CAN_BE_NIL/>
          </PARAM>
        </PARAMS>

      </METHOD>

      <METHOD name="destroy" generateAPI="false">
        <DESC>Destroy a Rhodes model object.</DESC>
      </METHOD>
      <METHOD name="canModify" deprecated="true" generateAPI="false">
        <DESC>Returns true if the Rhodes model object is not currently being synced (if it is being synced, you should
          disable editing of the object). 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.
        </DESC>
        <RETURN type="BOOLEAN"/>
      </METHOD>
      <METHOD name="save" generateAPI="false">
        <DESC>Saves the current Rhodes model object to the database.
        </DESC>
      </METHOD>
      <METHOD name="updateAttributes" generateAPI="false">
        <DESC>Updates the current Rho model object attributes and saves it to the database. This is the fastest way to
          add or update model attributes.
        </DESC>
        <PARAMS>
          <PARAM name="attributes" type="HASH">
            <DESC>List of attributes and their updated values, such as {"name" => "<NAME>.","address" => "555 5th
              St."}.
            </DESC>
          </PARAM>
        </PARAMS>
      </METHOD>

    </METHODS>

    <USER_OVERVIEW>
      <!--  More conversational style with INLINE SAMPLES, written in MarkDown -->
      <![CDATA[]]>

    </USER_OVERVIEW>
    <VER_INTRODUCED>1.0.0</VER_INTRODUCED>
    <PLATFORM>
      <!--  This section is used for the supported platform images at the top -->
    </PLATFORM>
    <EXAMPLES>
      <EXAMPLE title="ORM DeleteAll Method Examples">
        <SECTIONS>
          <SECTION>
            <DESC>
              Delete all Rhodes model objects for a source, filtering by conditions.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
Account.deleteAll(:conditions => {'industry'=>'electronics', 'website'=>'electronics.com'})]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[
Account.deleteAll();]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>

        </SECTIONS>
      </EXAMPLE>
      <EXAMPLE title="ORM Find Method Examples">
        <SECTIONS>

          <SECTION>
            <DESC>
              Find all objects for specific ORM model
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
accounts = Account.find(:all)]]>
              </RUBY>
              <JAVASCRIPT>

                <![CDATA[
vat accounts = Account.find('all');]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>

          <SECTION>
            <DESC>
              Find all objects for specific ORM model with conditions
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
Account.find(:all, :conditions => {'industry' => 'Technology'}) ]]>
              </RUBY>
              <JAVASCRIPT>

                <![CDATA[
var accounts = Account.find(
    'all',
    {
      conditions: {industry: 'Technology'}
    }
  ) ]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>

          <SECTION>
            <DESC>
              Use select option for retrieves some attributes of object.  You must pass "conditions" hash with Javascript implementation.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
accounts = Account.find(:all, :select => ['name','address'])
accounts[0].name
  #=> "<NAME> PLC 37862"
accounts[0].telephone
  #=> nil ]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[
var accounts = Account.find(
    'all',
    {
      conditions: {name:'address'},
      select: ['name','address']
    }
  );
accounts[0].get("name");  // "<NAME> PLC 37862"
accounts[0].get("telephone"); // nil ]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>

          <SECTION>
            <DESC>
              Order option is used to sort objects by one or more attributes.
              The order argument for find accepts several fORMs.


              Order by one attribute. Javascript must pass conditions hash.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
accounts = Account.find(
      :all,
      :order => 'name',
      :orderdir => 'DESC'
    ) ]]>
              </RUBY>
              <JAVASCRIPT>

                <![CDATA[
var accounts = Account.find(
    'all',
    {
      conditions: {"name":"industry"},
      order: 'name',
      orderdir: 'DESC'
    }
  ) ]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>

          <SECTION>
            <DESC>
              Order by multiple attributes. Javascript must pass conditions hash.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
accounts = Account.find(
      :all,
      :order => ['name', 'industry'],
      :orderdir => ['ASC', 'DESC']
    ) ]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[
var accounts = Account.find(
    'all',
    {
      conditions: {"name":"industry"},
      order: ['name', 'industry'],
      orderdir: ['ASC', 'DESC']
    }
  ); ]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>

          <SECTION>
            <DESC>
              Order by one attribute with a block.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
accounts = Account.find(:all, :order => 'name') do |x,y|
      y <=> x
    end ]]>
              </RUBY>
              <JAVASCRIPT>

                <![CDATA[
var accounts = Account.find(
    'all',
    {
      order: 'name',
      orderFunction: function (a, b) { return a <= b }
    }
  ); ]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>
          <SECTION>
            <DESC>
              Order with a block.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
accounts = Account.find(:all) do |item1,item2|
      item2.name <=> item1.name
    end ]]>
              </RUBY>
              <JAVASCRIPT>

                <![CDATA[
var accounts = Account.find(
    'all',
    {
      orderFunction: function (item1, item2) { return item1.name <= item2.name }
    }
  ); ]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>


        </SECTIONS>
      </EXAMPLE>
      <EXAMPLE title="ORM New and Create Method Examples">
        <SECTIONS>
          <SECTION>
            <DESC>
              Use method New for creating a new ORM object and assign given attributes.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
account = Account.new({"name" => "ABC Inc.", "address" => "555 5th St."})
account.name
  #=> "ABC Inc." ]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[
var account = Account.make({name: "ABC Inc.", address: "555 5th St."});
account.get("name") // "ABC Inc." ]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>
          <SECTION>
            <DESC>
              Use method Create for creating a new ORM object and save to the database.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
account = Account.create({"name" => "some new record", "industry" => "electronics"}) ]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[
var account = Account.create({name: "some new record", industry: "electronics"})  ]]>
              </JAVASCRIPT>
            </CODE>

          </SECTION>
        </SECTIONS>
      </EXAMPLE>
      <EXAMPLE title="ORM Paginate Method Example">
        <SECTIONS>
          <SECTION>
            <DESC>
              Paginate calls find with a limit on the # of records. This emulates rails' classic pagination syntax.
              Default page size is 10.


              Retrieve first 10 records:
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
Account.paginate(:page => 0) ]]>
              </RUBY>
            </CODE>
          </SECTION>

          <SECTION>
            <DESC>
              Retrieve records 21-40
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
Account.paginate(:page => 1, :perPage => 20) ]]>
              </RUBY>
            </CODE>
          </SECTION>

          <SECTION>
            <DESC>
              You can have conditions and order as well
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
Account.paginate(
  :page => 5,
  :conditions => {'industry' => 'Technology'},
  :order => 'name'
) ]]>
              </RUBY>
            </CODE>
          </SECTION>

        </SECTIONS>
      </EXAMPLE>
      <EXAMPLE title="ORM Sync and setNotification Method Example">
        <SECTIONS>
          <SECTION>
            <DESC>
              Start the sync process for a model. In this example, the value for @params[“sku”] — the value of the sku —
              must be URL encoded.
            </DESC>
            <CODE lang="ruby">
              <RUBY>
                <![CDATA[
Product.sync( url_for(:action => :sync_callback), "", false, "query=#{@params["sku"]}" ) ]]>
              </RUBY>
            </CODE>
          </SECTION>

          <SECTION>
            <DESC>
              Set a notification to be called when the sync is complete for this model. This is useful for example if
              you want to refresh the current list page or display an alert when new data is synchronized. See the sync
              notification docs for more infORMation.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
              Account.setNotification( url_for(:action => :sync_notify) ) ]]>
              </RUBY>
            </CODE>
          </SECTION>

        </SECTIONS>
      </EXAMPLE>
      <EXAMPLE title="ORM IsChanged Method Example">
        <SECTIONS>
          <SECTION>
            <DESC>
              Determine if a ORM model has local database changes that need to be synchronized.  Must enable sync to use this function.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
                def should_sync_product_object
  if Product.isChanged
    #... do stuff ...
  end
end  ]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[

  if (Product.haveLocalChanges()) {
      //... do stuff ...
    }
  ]]>
              </JAVASCRIPT>
            </CODE>
          </SECTION>
        </SECTIONS>
      </EXAMPLE>

      <EXAMPLE title="ORM Destroy Method Examples">
        <SECTIONS>
          <SECTION>
            <DESC>
              Destroy a Rhodes model object.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
@account = Account.find(:first)
@account.destroy]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[
var account = Account.find('first');
account.destroy();]]>
              </JAVASCRIPT>

            </CODE>

          </SECTION>
        </SECTIONS>
      </EXAMPLE>
      <EXAMPLE title="ORM UpdateAttributes Method Example">
        <SECTIONS>
          <SECTION>
            <DESC>Update the current ORM object’s attributes and saves it to the database.</DESC>
            <CODE>
              <RUBY>
                <![CDATA[
account = Account.find(
  :first,
  :conditions => {'name' => 'ABC Inc.'}
)
account.update_attributes({"name" => "ABC Inc.", "industry" => "Technology"})

account.industry
  #=> "Technology" ]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[
var account = Account.find("first", {conditions: {name: "ABC Inc."});
account.updateAttributes({name: "ABC Inc.", industry: "Technology"});
account.get("industry") // "Technology" ]]>
              </JAVASCRIPT>
            </CODE>
          </SECTION>
        </SECTIONS>
      </EXAMPLE>
      <EXAMPLE title="ORM Save Method Example">
        <SECTIONS>
          <SECTION>
            <DESC>Saves the current ORM object to the database.</DESC>
            <CODE>
              <RUBY>
                <![CDATA[
account = Account.new({"name" => "<NAME>", "industry" => "electronics"})
account.save ]]>
              </RUBY>
              <JAVASCRIPT>
                <![CDATA[
var account = Account.make({name: "<NAME>", industry: "electronics"});
account.save(); ]]>
              </JAVASCRIPT>
            </CODE>
          </SECTION>

        </SECTIONS>
      </EXAMPLE>
      <EXAMPLE title="ORM CanModify Method Example">
        <SECTIONS>
          <SECTION>
            <DESC>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. canModify 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.
            </DESC>
            <CODE>
              <RUBY>
                <![CDATA[
def edit
  @product = Product.find(@params['id'])
  if @product && !@product.canModify
    render :action => :show_edit_error
  else
    render :action => :edit
  end
end  ]]>
              </RUBY>
            </CODE>
          </SECTION>
        </SECTIONS>
      </EXAMPLE>
    </EXAMPLES>
  </MODULE>
</API>

{'fraction_non_alphanumeric': 0.12805580442851658, 'fraction_numerical': 0.002943811596057852, 'mean_word_length': 1.6569372024484244, 'pattern_counts': {'":': 4, '<': 1104, '<?xml version=': 0, '>': 1196, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2873682', 'n_tokens_mistral': 13638, 'n_tokens_neox': 12710, 'n_words': 3894}