changes and dev

This commit is contained in:
Yuri Kuznetsov
2013-12-27 13:53:47 +02:00
parent 910a6809c9
commit 65fdabf83c
5 changed files with 28 additions and 10 deletions
+1 -2
View File
@@ -72,8 +72,7 @@ class Repository extends \Espo\ORM\Repository
if (!in_array($id, $specifiedIds)) {
$toRemoveIds[] = $id;
}
}
}
foreach ($specifiedIds as $id) {
if (!in_array($id, $existingIds)) {
$this->relate($entity, $name, $id);
+3 -3
View File
@@ -678,7 +678,7 @@ abstract class Mapper implements IMapper
$valuesPart = implode(", ", $valArr);
$sql = $this->composeInsertQuery($this->toDb($entity->getEntityName()), $fieldsPart, $valuesPart);
if ($this->pdo->query($sql)) {
return $entity->id;
}
@@ -1074,7 +1074,7 @@ abstract class Mapper implements IMapper
protected function composeInsertQuery($table, $fields, $values)
{
$sql = "INSERT INTO {$table}";
$sql = "INSERT INTO `{$table}`";
$sql .= " ({$fields})";
if (!is_array($values)) {
$sql .= " VALUES ({$values})";
@@ -1087,7 +1087,7 @@ abstract class Mapper implements IMapper
protected function composeUpdateQuery($table, $set, $where)
{
$sql = "UPDATE {$table} SET {$set} WHERE {$where}";
$sql = "UPDATE `{$table}` SET {$set} WHERE {$where}";
return $sql;
}
+1 -1
View File
@@ -21,7 +21,7 @@ class MysqlMapper extends Mapper
$sql .= " DISTINCT";
}
$sql .= " {$select} FROM {$table}";
$sql .= " {$select} FROM `{$table}`";
if (!empty($joins)) {
$sql .= " {$joins}";
+2 -1
View File
@@ -9,9 +9,10 @@ class EntityCollection implements \Iterator, \Countable, \ArrayAccess, \Seekable
private $entityName;
private $position = 0;
protected $container = array();
public function __construct(array $data, $seed = null, EntityFactory $entityFactory = null)
public function __construct($data, $seed = null, EntityFactory $entityFactory = null)
{
$this->container = $data;
+21 -3
View File
@@ -79,7 +79,8 @@ class Record extends \Espo\Core\Services\Base
{
$entity = $this->getRepository()->get($id);
if (!empty($entity) && !empty($id)) {
$this->loadLinkMultipleFields($entity);
$this->loadLinkMultipleFields($entity);
$this->loadParentNameFields($entity);
}
return $entity;
}
@@ -105,6 +106,23 @@ class Record extends \Espo\Core\Services\Base
}
}
protected function loadParentNameFields($entity)
{
$fieldDefs = $this->getMetadata()->get('entityDefs.' . $this->entityName . '.fields', array());
foreach ($fieldDefs as $field => $defs) {
if ($defs['type'] == 'linkParent') {
$id = $entity->get($field . 'Id');
$scope = $entity->get($field . 'Type');
if ($scope) {
if ($foreignEntity = $this->getEntityManager()->getEntity($scope, $id)) {
$entity->set($field . 'Name', $foreignEntity->get('name'));
}
}
}
}
}
protected function getSelectManager()
{
if (empty($this->selectManager)) {
@@ -118,11 +136,11 @@ class Record extends \Espo\Core\Services\Base
// TODO validate $data
$entity = $this->getEntity();
$entity->set($data);
$entity->set($data);
if ($this->getRepository()->save($entity)) {
return $entity;
}
}
throw new Error();
}