I have create a fixed schema model with ruby code. Can i get acess to this model from js using RhomJs(5.2.2)

S Stepan Boichyshyn 3 years 6 months ago
1 1 0

I have create a fixed schema model with ruby code. Can i get acess to this model from js using RhomJs

class Cart
  include Rhom::FixedSchema

  # Uncomment the following line to enable sync with Cart.
  # enable :sync
  belongs_to :user_id, "User"
  #add model specific code here
  property :name, :string
  property :user_id, :integer
  set :schema_version, '1.1'
end

But

var cartModel = Rho.ORM.getModel('Cart');
function createCart(){
  var cart = cartModel.create({name: "Script Cart"});
  alert(cartModel.find("count"))
}

get an error -  TypeError: 'undefined' is not an object (evaluating 'cartModel.create')

And

var cartModel = Rho.ORM.addModel(function(model) {
  model.modelName('Cart');
    model.property('name','string');
});

function createCart(){
  var cart = cartModel.create({name: "Script Cart"});
  alert(cartModel.find("count"))

}

Create recirds in new PropertyBag Model called Cart

Can i get access to exist FixedSchema Cart model using Js

Please Register or Login to post a reply

1 Replies

S Stepan Boichyshyn

you need add

model.enable('fixedSchema');

to model config/ And now you can use your fixed schema model created by ruby in js code

Result

var cartModel = Rho.ORM.addModel(function(model) {
  model.modelName('Cart');
    model.property('name','string');
model.enable('fixedSchema');
});

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