forked from propelorm/Propel2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marc Philip Scholten
committed
Oct 10, 2013
1 parent
ecef289
commit e1f9f06
Showing
5 changed files
with
84 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/Propel/Generator/Builder/Om/templates/Object/_hydrate.php.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,70 @@ | |||
/** | |||
* Hydrates (populates) the object variables with values from the database resultset. | |||
* | |||
* An offset (0-based \"start column\") is specified so that objects can be hydrated | |||
* with a subset of the columns in the resultset rows. This is needed, for example, | |||
* for results of JOIN queries where the resultset row includes columns from two or | |||
* more tables. | |||
* | |||
* @param array $row The row returned by DataFetcher->fetch(). | |||
* @param int $startcol 0-based offset column which indicates which restultset column to start with. | |||
* @param boolean $rehydrate Whether this object is being re-hydrated from the database. | |||
* @param string $indexType The index type of $row. Mostly DataFetcher->getIndexType(). | |||
One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME | |||
* TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM. | |||
* | |||
* @return int next starting column | |||
* @throws PropelException - Any caught Exception will be rewrapped as a PropelException. | |||
*/ | |||
public function hydrate($row, $startcol = 0, $rehydrate = false, $indexType = TableMap::TYPE_NUM) | |||
{ | |||
try { | |||
{% set n = 0 %} | |||
{% for column in builder.table.columns %} | |||
{% set n = loop.index0 %} | |||
{% if not column.lazyLoad %} | |||
$col = $row[TableMap::TYPE_NUM == $indexType ? {{ loop.index0 }} + $startcol : {{ builder.tableMapClassName }}::translateFieldName('{{ column.phpName }}', TableMap::TYPE_PHPNAME, $indexType)]; | |||
{% if column.lobType and builder.platform.hasStreamBlobImpl %} | |||
$this->{{ column.name|lower }} = stream_get_contents($col); | |||
{% elseif column.lobType %} | |||
if (null !== $col) { | |||
$this->{{ column.name|lower }} = fopen('php://memory', 'r+'); | |||
fwrite($this->{{ column.name|lower }}, $col); | |||
rewind($this->{{ column.name|lower }}); | |||
} else { | |||
$this->{{ column.name|lower }} = null; | |||
} | |||
{% elseif column.temporalType %} | |||
{% if builder.invalidTemporalString(column) is not null %} | |||
if ($col === '{{ builder.invalidTemporalString }}') { | |||
$col = null; | |||
} | |||
{% endif %} | |||
|
|||
$this->{{ column.name|lower }} = (null !== $col) ? PropelDateTime::newInstance($col, null, '{{ builder.buildProperty('dateTimeClass')|default('\DateTime') }}') : null; | |||
{% elseif column.phpPrimitiveType %} | |||
$this->{{ column.name|lower }} = (null !== $col) ? ({{ column.phpType }}) $col : null; | |||
{% elseif column.phpArrayType %} | |||
$this->{{ column.name|lower }} = $col; | |||
$this->{{ column.name|lower }}_unserialized = null; | |||
{% else %} | |||
$this->{{ column.name|lower }} = $col; | |||
{% endif %} | |||
{% endif %} | |||
{% endfor %} | |||
|
|||
{% if builder.buildProperty('addSaveMethod') %} | |||
$this->resetModified(); | |||
{% endif %} | |||
$this->setNew(false); | |||
|
|||
if ($rehydrate) { | |||
$this->ensureConsistency(); | |||
} | |||
|
|||
return $startcol + {{ n }}; // {{ n }} = {{ builder.tableMapClassName }}::NUM_HYDRATE_COLUMNS. | |||
|
|||
} catch (Exception $e) { | |||
throw new PropelException("Error populating {{ builder.objectClassName }} object", 0, $e); | |||
} | |||
} |