Skip to content

Commit

Permalink
Add TODO.md
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Apr 7, 2013
1 parent a8fdb5e commit dfe2f49
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
5 changes: 5 additions & 0 deletions TODO.md
@@ -0,0 +1,5 @@
TODO
====

1. Refactor update, create method calls to `rawUpdate` and `rawCreate`.

41 changes: 33 additions & 8 deletions src/LazyRecord/BaseModel.php
Expand Up @@ -918,23 +918,22 @@ public function _update( $args , $options = array() )
return $this->reportError("The value of primary key is undefined.");
}

$validationFailed = false;
$validationResults = array();


$conn = $this->getConnection( $dsId );
$dsId = $this->getWriteSourceId();
$sql = null;
$vars = null;

$validationFailed = false;
$validationResults = array();

try
{
$args = $this->beforeUpdate($args);
$origArgs = $args;

$args = $this->filterArrayWithColumns($args);
$sql = null;
$vars = null;

$dsId = $this->getWriteSourceId();
$conn = $this->getConnection( $dsId );

foreach( $this->getSchema()->getColumns() as $n => $c ) {
// if column is required (can not be empty)
Expand Down Expand Up @@ -989,7 +988,6 @@ public function _update( $args , $options = array() )
}

$query = $this->createQuery( $dsId );

$query->update($args)->where()
->equal( $k , $kVal );

Expand Down Expand Up @@ -1030,6 +1028,33 @@ public function _update( $args , $options = array() )
}



/**
* Simply run update without validation
*
* @param array $args
*/
public function rawUpdate($args)
{
$conn = $this->getConnection( $dsId );
$dsId = $this->getWriteSourceId();
$k = $this->getSchema()->primaryKey;
$kVal = isset($args[$k])
? $args[$k] : isset($this->_data[$k])
? $this->_data[$k] : null;

$query = $this->createQuery( $dsId );
$query->update($args)->where()
->equal( $k , $kVal );

$sql = $query->build();
$vars = $query->vars;
$stm = $this->dbPrepareAndExecute($conn, $sql, $vars);
$this->_data = array_merge($this->_data,$args);
}



/**
* Save current data (create or update)
* if primary key is defined, do update
Expand Down

0 comments on commit dfe2f49

Please sign in to comment.