platanus / angular-restmod

Rails inspired REST-API ORM for Angular
http://platanus.github.io/angular-restmod/
MIT License
1.18k stars 87 forks source link

$new does not populate primary key field. #386

Open werner291 opened 8 years ago

werner291 commented 8 years ago

Hello!

I love this library, it handles collections and relations so much better than ngResource (that is: it handles them at all.)

The issue:

Calling $new( ) does populate the $pk field, but not the "id" field.

restmodProvider.rebase({
    $config: {
        primaryKey: 'id'
    },
    })

var SomeModel = restmod.model('/foo')

SomeModel.$new(1).id // <== Is undefined.

A workaround at the moment is with this hook:

'after-init': function() {
if (typeof this.id === 'undefined') {
    this.id = this.$pk;
}
}