Skip to content

Nested relationships #9

@SinisterMinister

Description

@SinisterMinister

Need to have it where we can traverse the relationships of an object. I'm imagining a contract that will look something like this:

var bio;

/**
 * Loading the relationship with the model. This is the prefered way.
 */
ORM.factory('user').with('profile').find(1).then(function (user) {
    // Returns the biography
    bio = user.get('profile.biography');
});

/**
 * Without preloaded relationship and return a promise from get(). I'm not sure
 * this is the best way to go as having multiple return types from get() smells
 * bad. If we decide that we don't want to do this, we should throw an 
 * exception.
 */
ORM.factory('user').find(1).then(function (user) {
    return user.get('profile.biography');
}).then(function (biography) {
    bio = biography;
});

/**
 * I'd prefer to have a different function getting nested date without
 * prefetching. Still need the promise though, which sucks. In ES6 we can use
 * generators to get around this.
 */
ORM.factory('user').find(1).then(function (user) {
    return user.getNested('profile.biography');
}).then(function (biography) {
    bio = biography;
});

I think long term, we need to look at ES6 generators + TaskJS for this kind of behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions