3 Replies Latest reply on Nov 8, 2013 7:05 AM by BHAKTA RANJAN SATAPATHY

    Does fixedSchema work in a javascript model?

      <!DOCTYPE html>

      <html>

      <head>

      <meta charset="ISO-8859-1">

      <title>Insert title here</title>

      <script src="/public/api/rhoapi-modules.js" type="text/javascript"></script>

      </head>

      <body>

          <script type="text/javascript">

              var productModel = Rho.ORM.addModel(function(model){

                    model.modelName("Product");

                    model.enable("fixedSchema");

                   model.property("name","string");

                    model.property("brand","string");

                    model.property("price","float");

                    model.set("partition","user");

              });

       

              // create model object and save it to database

              var product = productModel.create({

                    brand: 'Apple',

                   name: 'iPhone5',

                    price: 199.99});

       

              // read product from database

              var product = productModel.find('first');

                  product.get('brand'); // Apple

                  product.get('name'); // iPhone5

         

          </script>

      </body>

      </html>

       

      This code results in the following error when running in the RhoSimulator

      TypeError: Result of expression '$'  [undefined] is not an object on line 1276 rhoapi-modules.js

       

      I have tried changing the line  model.enable("fixedSchema"); to  model.enable("propertyBag"); and this works fine.

       

      Am I missing something or is this a bug?

        • Re: Does fixedSchema work in a javascript model?
          BHAKTA RANJAN SATAPATHY

          Hi,

          If you will add jquery to your html, you will not get any error, and will work fine.

           

          <script src="/public/jquery/jquery-1.9.1.min.js" type="text/javascript"></script>

          <script src="/public/api/rhoapi-modules.js" type="text/javascript"></script>

           

           

           

           

          Thanks

          Bhakta

            • Re: Does fixedSchema work in a javascript model?

              Added jQuery and I am still getting the same error.

               

              <!DOCTYPE html>

              <html>

              <head>

              <meta charset="ISO-8859-1">

              <title>Insert title here</title>

              <script src="/public/api/rhoapi-modules.js" type="text/javascript"></script>

              <script src="/public/jquery/jquery-1.9.1.min.js" type="text/javascript"></script>

              </head>

              <body>

                  <script type="text/javascript">

                      var productModel = Rho.ORM.addModel(function(model){

                            model.modelName("Product");

                            model.enable("fixedSchema");

                           model.property("name","string");

                            model.property("brand","string");

                            model.property("price","float");

                            model.set("partition","user");

                      });

               

                      // create model object and save it to database

                      var product = productModel.create({

                            brand: 'Apple',

                           name: 'iPhone5',

                            price: 199.99});

               

                      // read product from database

                      var product = productModel.find('first');

                          product.get('brand'); // Apple

                          product.get('name'); // iPhone5

                 

                  </script>

              </body>

              </html>