1 Reply Latest reply on Feb 19, 2014 12:00 AM by BHAKTA RANJAN SATAPATHY

    Issue with RHOM ORM javacript - for creating multiple models

      I am using Rhomobile suite 4.0.0. I want to create multiple models for my application using rhomobile api 4.0. For reference, I m following the link ‘http://docs.rhomobile.com/en/4.0.0/api/Orm#e0’

       

       

      Here is my code:

       

      <script type="text/javascript">

       

      function create_Model1() {

             var model = get_Model1();

             if (!model) {

                    model = Rho.ORM.addModel(

                           function(model) {

      model.modelName('Model1');

      model.property('A','string');

                           model.property('B','string');                  

                           model.enable('propertyBag');

                    });

             }

             return model;

      }

       

      function get_Model1 () {

             var model = Rho.ORM.getModel('Model1');

             return model;

      }

       

      </script>

       

       

      <script type="text/javascript">

       

      function create_Model2() {

             var model = get_Model2();

             if (!model) {

                    model = Rho.ORM.addModel(

                           function(model) {

      model.modelName('Model2');

      model.property('C','string');

                           model.property('D','string');                  

                           model.enable('propertyBag');

                    });

             }

             return model;

      }

       

      function get_Model2 () {

             var model = Rho.ORM.getModel('Model2');

             return model;

      }

       

      </script>

       

       

      <script type="text/javascript">

       

      function create_Model3() {

             var model = get_Model3();

             if (!model) {

                    model = Rho.ORM.addModel(

                           function(model) {

      model.modelName('Model3');

      model.property('A','string');

                           model.property('B','string');                  

                           model.enable('propertyBag');

                    });

             }

             return model;

      }

       

      function get_Model3() {

             var model = Rho.ORM.getModel('Model3');

             return model;

      }

      </script>

       

       

      I am using ruby in my project. From ruby actions, I am invoking these 3 different javascript functions. First model is created successfully. When I try to create second model, I am getting below error:

       

      could not execute statement: 19; Message: column source_id is not unique

       

       

      However instead of using ‘model.enable('propertyBag') if I use model.set("partition", "local") & model.set("partition", "user"), then I can able to create 2 models successfully. But my requirement is to create multiple models may be around 7 or 8 models. Please provide me suitable solution.  Also explain the use of setting model.set("partition", "user"), & model.set("partition", "local").



      Thanks,

      Hariharan.