SchizoDuckie / CreateReadUpdateDelete.js

CreateReadUpdateDelete.js aims to bring you a tiny footprint (18kb compressed), platform independent ORM/ActiveRecord implementation for Javascript that works flawlessly on SQLite / WebSQL databases, or any flavor of remote database you can think of via serverside JSON API. Written in Plain Old JavaScript without any framework dependencies, you can use this with Mootools, Jquery, Zepto, Ember, or whatever your drug of choice is.
http://schizoduckie.github.io/CreateReadUpdateDelete.js/
MIT License
38 stars 5 forks source link

Using FIND or FINDONE on related tables #9

Closed MarioVanDenEijnde closed 7 years ago

MarioVanDenEijnde commented 8 years ago

Hello SchizoDuckie,

Adding a relationship to a table probably modifies the object structure? I ask because after adding the relationship below function findFood() only returns objects and I don't know how to get inside the objects. The function findFoodFav = the related table and also only return an [object Object]

function findFood(){
    CRUD.Find('Food', {}, { limit: '0,10000' }).then(function(results) {
        return results.map(function(entity) {return entity.asObject()})
        }).then(function(result){
            console.log(JSON.stringify("Food: "+result));
    });
}

function findFoodFav(){     
    CRUD.FindOne('Food', { ID_Food: 3}).then(function(food) {
        food.Find('FoodFav').then(function(foodfav) {
            console.log("FoodFav: "+foodfav);
        });
    });
}

Can you advise?

Kind regards, Mario

MarioVanDenEijnde commented 8 years ago

Hello SchizoDuckie,

I think I am moving forward with my trial and errors. But Can you tell me how to do a connection to an existing actor?

CRUD.setAdapter(new CRUD.SQLiteAdapter('createreadupdatedelete_single', {
    estimatedSize: 25 * 1024 * 1024
})).then(function() {

    var cptn = new Role();
    cptn.name = 'Captain Jack Sparrow';

    var actor = new Actor();
    actor.firstName = 'Johnny';
    actor.lastName = 'Depp';
    actor.gender = 'm';

    cptn.Connect(actor);

});
SchizoDuckie commented 7 years ago

Please refer to the updated docs here : https://github.com/SchizoDuckie/CreateReadUpdateDelete.js