JayData- Retrieval of Complex Data From Database

57 Views Asked by At

Saving the records in jaydata- web sql database is successful. How do we retrieve the record(Todo) from the database including Location.

$data.Entity.extend("Location", {
    City: { type: String },
    Country: { type: String }
});
$data.Entity.extend("Todo", {
    Id: { type: "int", key: true, computed: true },
    Task: { type: String, required: true, maxLength: 200 },
    DueDate: { type: Date },
    Completed: { type: Boolean },
    Location: { type: Location }
});

$data.EntityContext.extend("TodoDatabase", {
    Todos: { type: $data.EntitySet, elementType: Todo }
});
1

There are 1 best solutions below

0
Robesz On

Relationships are lazy-loaded by JayData. You can use the .include('NavigationPropertyName') operator, which performs a JOIN in WebSQL.

Example:

db.Todos.include('Location').toArray(...)

One other thing is needed to make this work: update entity context with the location entityset.

$data.EntityContext.extend("TodoDatabase", {
    Todos: { type: $data.EntitySet, elementType: Todo },
    Locations: { type: $data.EntitySet, elementType: Location } // <--add this
});

You can read more on JayData entity releationships here - JayData and relationships