     else
       @
 
-  findByIdAndUpdate: (id, update, options, cb) ->
-    @returnArray = false
-    @query = 'SELECT TOP 1 * FROM ' + @table + ' WHERE _id = ' + id
-    if cb?
-      @exec cb
-    else
-      @
+  findByIdAndUpdate: (id, obj, cb) ->
+    @returnArray = true
+    value = ""
+    @query = 'UPDATE ' + @table + ' SET '
+    separator = ''
+    for key, value of obj
+      if key isnt @idColumn
+        @query += separator + ' ' + key + '=' + value
+        separator = ','
+    @query += ' WHERE ' + @idColumn + ' = ' + id
+    @exec cb
 
   remove: (query, cb) ->
     @returnArray = false

  if def.options?.collectionName?
    collectionName = def.options.collectionName

  qb = new def.Qb(collectionName, dbConnection)
  qb.modelName = def.name
  qb


sqlHelper = require './sqlHelper'

class QueryBuilder
  constructor: (@table, @dbConnection, @idColumn) ->
    @query = ""
    @returnArray = true

