summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChris Cornutt <chris.cornutt@hp.com>2015-01-16 15:39:35 -0600
committerChris Cornutt <chris.cornutt@hp.com>2015-01-16 15:39:35 -0600
commitd2b8a297f1c395ba56227cad65fbce45ece1a0a2 (patch)
tree4fa89ea76b9868ed6aa8ac832335a103e7ca05b3 /src
parent48685d08198a25358bee38b76f6f30765c753705 (diff)
downloadgatekeeper-d2b8a297f1c395ba56227cad65fbce45ece1a0a2.zip
gatekeeper-d2b8a297f1c395ba56227cad65fbce45ece1a0a2.tar.gz
gatekeeper-d2b8a297f1c395ba56227cad65fbce45ece1a0a2.tar.bz2
adding relation handling (create)
Diffstat (limited to 'src')
-rw-r--r--src/Psecio/Gatekeeper/DataSource/Mysql.php24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/Psecio/Gatekeeper/DataSource/Mysql.php b/src/Psecio/Gatekeeper/DataSource/Mysql.php
index f15f6ee..77de1d8 100644
--- a/src/Psecio/Gatekeeper/DataSource/Mysql.php
+++ b/src/Psecio/Gatekeeper/DataSource/Mysql.php
@@ -89,13 +89,24 @@ class Mysql extends \Psecio\Gatekeeper\DataSource
*/
public function create(\Modler\Model $model)
{
+ $relations = array();
+ $properties = $model->getProperties();
+ $other = array();
$data = $model->toArray();
+
+ // Remove the ones without a column
+ foreach ($data as $index => $item) {
+ // Check the property to see if it's a relation
+ if ($properties[$index]['type'] == 'relation') {
+ $relations[$index] = $item;
+ unset($data[$index]);
+ }
+ }
+
$data['created'] = date('Y-m-d H:i:s');
$data['updated'] = date('Y-m-d H:i:s');
list($columns, $bind) = $this->setup($data);
- $properties = $model->getProperties();
-
foreach ($columns as $index => $column) {
$colName = $properties[$column]['column'];
$columns[$index] = $colName;
@@ -105,7 +116,14 @@ class Mysql extends \Psecio\Gatekeeper\DataSource
.' ('.implode(',', $columns).') values ('.implode(',', array_values($bind)).')';
$result = $this->execute($sql, $data);
if ($result !== false) {
- $this->id = $this->getDb()->lastInsertId();
+ $model->id = $this->getDb()->lastInsertId();
+ }
+
+ // Now handle the relations - for each of them, get the model, make it and save it
+ foreach ($relations as $index => $item) {
+ $relation = $properties[$index];
+ $instance = new $relation['relation']['model']($this);
+ $instance->create($model, $item);
}
return $result;