Skip to content

Commit

Permalink
fix(): removed arrow functions
Browse files Browse the repository at this point in the history
removed arrow functions as they are still not supported in iojs
  • Loading branch information
thetutlage committed Oct 3, 2015
1 parent 56e668c commit 45f4740
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/Orm/Proxy/Model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
require('harmony-reflect')

const proxy = require('./proxy')
const helper = require('./helper')
const helper = require('./helper')
const StaticProxy = require('../Static')
const Ioc = require('adonis-fold').Ioc
const relation = require('./relation')
Expand Down Expand Up @@ -64,12 +64,14 @@ class Model {
* @public
*/
create (values) {
const self = this

/**
* here we consume the create method from model
* constructor and set primaryKey value to
* value returned by create method.
*/
return new Promise((resolve,reject) => {
return new Promise(function (resolve,reject) {
/**
* throw an error if trying to save multiple
* rows via model instance.
Expand All @@ -79,14 +81,14 @@ class Model {
}

let isMutated = !values
values = values || this.attributes
values = values || self.attributes

this.constructor
.create(values, isMutated, this.connection)
.then ((response) => {
self.constructor
.create(values, isMutated, self.connection)
.then( function(response) {
if(response[0]){
this.attributes = helper.mutateRow(this,values)
this.attributes[this.constructor.primaryKey] = response[0]
self.attributes = helper.mutateRow(self,values)
self.attributes[self.constructor.primaryKey] = response[0]
}
resolve(response)
}).catch(reject)
Expand Down Expand Up @@ -139,20 +141,22 @@ class Model {
* @public
*/
forceDelete () {
const self = this

/**
* one can only delete existing model. Here we make
* sure this model is initiated after db fetch.
*/
if (!helper.isFetched(this)) {
throw new Error(`You cannot delete a fresh model instance , trying fetching one using find method`)
}
return new Promise((resolve, reject) => {
this
return new Promise(function (resolve, reject) {
self
.constructor
.forceDelete(this.connection)
.then((response) => {
this.attributes = {}
this.connection = this.constructor.database.table(this.constructor.table)
.forceDelete(self.connection)
.then(function (response) {
self.attributes = {}
self.connection = self.constructor.database.table(self.constructor.table)
resolve(response)
})
.catch(reject)
Expand Down
Binary file modified test/implementation/storage/blog.sqlite3
Binary file not shown.
Binary file modified test/unit/storage/test.sqlite3
Binary file not shown.

0 comments on commit 45f4740

Please sign in to comment.