Skip to content

Commit

Permalink
Now find method also mutate values
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Sep 11, 2015
1 parent b7bf23e commit 03fc3eb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Orm/Proxy/Static/hijacker.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ hijacker.find = function (target, id) {
.where(target.primaryKey, id)
.first()
.then(function (values) {
values = helpers.mutateRow(target, values)
let instance = new target(values)
instance.connection.where(target.primaryKey, id)
resolve(instance)
Expand Down
Binary file modified test/implementation/storage/blog.sqlite3
Binary file not shown.
43 changes: 43 additions & 0 deletions test/unit/model.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,49 @@ describe('Model', function () {

})

it('should mutate values for those whose getters are defined' , function (done) {

class User extends Model{

getUsername(value){
return value.toUpperCase()
}

}

User.database = db;
User = User.extend()

User
.where('id',1)
.fetch()
.then (function (user) {
expect(user.first().username).to.equal('NIKK')
done()
}).catch(done)

})

it('should mutate values when initiating model using find method', function (done) {

class User extends Model{
getUsername(value){
return value.toUpperCase()
}
}

User.database = db
User = User.extend()

User
.find(1)
.then (function (user) {
expect(user.username).to.equal('NIKK')
done()
}).catch(done)

})

it('should insert mutated values inside database using create method directly' , function () {

class User extends Model{
Expand Down

0 comments on commit 03fc3eb

Please sign in to comment.