1602 / compound

MVC framework. Built on Node.JS. Works on server and browser.
http://compoundjs.com
1.6k stars 182 forks source link

Compound JS Relationship Access - Does not work #525

Closed mike-wade closed 11 years ago

mike-wade commented 11 years ago

I posted http://stackoverflow.com/questions/16132102/compound-js-relationship-access and have had a massive 71 views to date, with no solution, I also posted this in the mailing list but no one has been able to help so far. So hopefully someone here will be able to sort my code out :smile:.

Here is the code I am having issue with (more detail on SO).

Schema:

var User = describe('User', function () {
    property('name', String);
    property('email', String);
    property('password', String);
    set('restPath', pathTo.users);
});

var Message = describe('Message', function () {
    property('userId', String, { index : true });
    property('content', String);
    property('timesent', Date, { default : Date });
    property('channelid', String);
    set('restPath', pathTo.messages);
});

Message.belongsTo(User, {as: 'author', foreignKey: 'userId'});
User.hasMany(Message, {as: 'messages',  foreignKey: 'userId'});

Action:

action(function show() {
    this.title = 'User show';

    var that = this;
    this.user.messages.build({content:"bob"}).save(function(){
        that.user.messages(function(err,message){
            console.log('Messages:');
            console.log(message);
        });
    });
    // ... snip ...
    }
});
anatoliychakkaev commented 11 years ago

I posted answer :)

On Wed, May 8, 2013 at 9:15 PM, Michael Wade notifications@github.comwrote:

I posted http://stackoverflow.com/questions/16132102/compound-js-relationship-accessand have had a massive 71 views to date, with no solution, I also posted this in the mailing list but no one has been able to help so far. So hopefully someone here will be able to sort my code out [image: :smile:].

Here is the code I am having issue with (more detail on SO).

Schema:

var User = describe('User', function () { property('name', String); property('email', String); property('password', String); set('restPath', pathTo.users);}); var Message = describe('Message', function () { property('userId', String, { index : true }); property('content', String); property('timesent', Date, { default : Date }); property('channelid', String); set('restPath', pathTo.messages);}); Message.belongsTo(User, {as: 'author', foreignKey: 'userId'});User.hasMany(Message, {as: 'messages', foreignKey: 'userId'});

Action:

action(function show() { this.title = 'User show';

var that = this;
this.user.messages.build({content:"bob"}).save(function(){
    that.user.messages(function(err,message){
        console.log('Messages:');
        console.log(message);
    });
});
// ... snip ...
}});

— Reply to this email directly or view it on GitHubhttps://github.com/1602/compound/issues/525 .

mike-wade commented 11 years ago

No joy with that solution yet :(

mike-wade commented 11 years ago

@anatoliychakkaev Any more suggestions? Updated the question on SO.