FYI - Datagraph with Objects and Collections

This post demonstrates real examples of working with Object types in different Collections with FatFractal.

The following Models are used with this post

function Movie() {
    this.title = null;
    this.description = null;
    this.year = null;
    return this;
}

function Actor() {
    this.firstName = null;
    this.lastName = null;
    return this;
}

You can see the data created by this app using the FatFractal DataBrowser ( here )

Create a Movie in the Movies collection

var m = new Movie();
m.title = "Argo";
m.description = "Argo is a 2012 historical drama thriller film directed by Ben Affleck.";
m.year =2012;
ff.createObjAtUri(m, "/Movies");


Create an Actor in the Actors collection

var a = new Actor();
a.firstName = "Ben";
a.lastName = "Affleck";
ff.createObjAtUri(a, "/Actors");


Create a Movie in the Favs collection

var m = new Movie();
m.title = "Argo";
m.description = "Argo is a 2012 historical drama thriller film directed by Ben Affleck.";
m.year =2012;
ff.createObjAtUri(m, "/Favs");


Create an Actor in the Favs collection

var a = new Actor();
a.firstName = "Ben";
a.lastName = "Affleck";
ff.createObjAtUri(a, "/Favs");


Create an Actor in the Movies collection (doh!)

var a = new Actor();
a.firstName = "Ben";
a.lastName = "Affleck";
ff.createObjAtUri(a, "/Movies");

Note: this is not allowed and should generate an error.


Get all the Movies from the Favs collection

ff.getArrayFromUri("/ff/resources/Favs/(clazz eq 'Movie')", function(r) {
    // handle success
}, function(code,message){
    // handle error
});


Get all the Actors from the Favs collection

ff.getArrayFromUri("/ff/resources/Favs/(clazz eq 'Actor')", function(r) {
    // handle success
}, function(code,message){
    // handle error
});


Get all the objects from the Favs collection

ff.getArrayFromUri("/ff/resources/Favs/", function(r) {
    // handle success
}, function(code,message){
    // handle error
});