How get records from DB using Js Rhom(FixedSchema)

// Expert user has replied.
S Stepan Boichyshyn 3 years ago
1 2 0

I have some model Cart. I can create a new ecords using Rhome as js code. But ho i can get records from database?

var cartModel = Rho.ORM.addModel(function(model) {
  model.modelName('Cart');
    model.property('name','string');
model.enable('fixedSchema');
});
I can use model function to get query

function getCart(){cartModel.find("first")}
But how get attributes from object? cartModel.find("first")  .name? or ["name"] does not work.And how get attributes from many records?

function getCart(){cartModel.find("all")}
AAartModel.find("first") car tModel.find("first")

Please register or login to post a reply

2 Replies

J Joydeep Chakraborty

Hi Stepan,
Are you being able to ge the records now?
Regards,
Joydeep

J Joydeep Chakraborty

Does the example shown in doc not work for you? In the example they are using get property to retrieve the property value.
Rhomobile | ORM

var productModel = Rho.ORM.addModel(function(model){ model.modelName("Product"); model.enable("sync"); 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

Another way is you can use vars method to get that with find all.Please see this for more information on how to access different properties of the model.
Rhomobile | [Your-OrmModel]
In your case,

function getCart()
{
var myobjarray=cartModel.find("all");
var index;
for(index=0;index

CONTACT
Can’t find what you’re looking for?