1

I've a customized mechanism to define classes in JavaScript as below:

Tools.User = Tools.Class.define("Tools.User", Tools.Entity, {
    Id: { type: "int", key: true, computed: true },
    IsActive: { type: Boolean },
    IsAdmin: { type: Boolean },
    LName: { type: String },
    FName: { type: String },
    FullName: { get: function () { return this.FName + " " + this.LName; }, Type: String },
    init: function (name, lname) {
        this.IsAdmin = false;
        this.IsActive = true;
        this.FName = name;
        this.LName = lname;
        Tools.Entity.call(this, arguments);
    },
    onEndEdit: function () {

        if (this.IsActive == false && this.IsAdmin == true) {
            throw new Error(Messages.AdminCanNotBeDisabled);
        }

        this.parentClass.onEndEdit();

    },
    deActivate: function () {

        if (this.IsAdmin == true) {
            throw new Error(Messages.AdminCanNotBeDisabled);
        }

        this.IsActive = false;
    }
});

As you can see, it supports virtual/override, auto implemented properties, constructor and so on.

I want to use my own classes in JayData. To do that I developed this lines:

$data.EntityContext.extend("Tools.AppDb", {
    Users: { type: $data.EntitySet, elementType: Tools.User }
});

var appDb = new Tools.AppDb({
    provider: 'indexedDb', databaseName: 'AppDb'
});

appDb.onReady(function () {

});

It's clear that it's impossible to work with Jaydata in this way. But how can I achieve this goal with minimum changes in my codes ?

I think that error message of this is not useful but this is an error message:

Uncaught TypeError: Cannot call method 'getPublicMappedProperties' of undefined 
Yaser Moradi
  • 3,267
  • 3
  • 24
  • 50

1 Answers1

1

JayData can operate on JayData entities in order to track changes and make the storage-independent data management possible.

So the elementType of the Users EntitySet should be derived from $data.Entity:

$data.Entity.extend("Todo", {
    Id: { type: "int", key: true, computed: true },
    Task: { type: String, required: true, maxLength: 200 },
    DueDate: { type: Date },
    Completed: { type: Boolean }
});
Robesz
  • 1,646
  • 11
  • 13
  • Thanks for your answer, I've developed several project based on JayData, and I know its foundation. Design of JayData is very good, but for now, I want to use my own entities, what can I do ? where is a start point for this ? Is there any sample, if you want I can inherit my Entity class from $data.Entity class. Best regards. – Yaser Moradi Jan 18 '14 at 13:54
  • if I have var temp = new Todo(someData), how can I get the key name (which is Id)? – Kim Honoridez Apr 09 '15 at 09:31