Merge branch 'master' of ssh://172.20.0.1/var/git/espo/backend
This commit is contained in:
@@ -34,12 +34,19 @@ class Links
|
||||
if (isset($link['params'])) {
|
||||
return isset($link['params']['entity']) ? $link['params']['entity'] : $entityName;
|
||||
}
|
||||
/*if (!isset($link['entity']) && isset($link['entities'])) {
|
||||
return $link['entities'];
|
||||
} */
|
||||
|
||||
return isset($link['entity']) ? $link['entity'] : $entityName;
|
||||
}
|
||||
|
||||
public function isMethodExists($methodName)
|
||||
{
|
||||
if (method_exists($this, $methodName) || method_exists($this->getRelations(), $methodName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function process($method, $entityName, $link, $foreignLink = array())
|
||||
{
|
||||
@@ -65,78 +72,58 @@ class Links
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
//END: hardcode
|
||||
|
||||
} //END: hardcode
|
||||
|
||||
if (method_exists($this, $method)) {
|
||||
return $this->$method($params, $foreignParams);
|
||||
} else if (method_exists($this->getRelations(), $method)) {
|
||||
return $this->getRelations()->$method($params, $foreignParams);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected function belongsTo($params, $foreignParams)
|
||||
{
|
||||
return $this->getRelations()->belongsTo($params, $foreignParams);
|
||||
}
|
||||
|
||||
//TODO: hook for teams
|
||||
protected function hasMany($params, $foreignParams)
|
||||
{
|
||||
return $this->getRelations()->hasMany($params, $foreignParams);
|
||||
}
|
||||
|
||||
|
||||
protected function hasManyHasMany($params, $foreignParams)
|
||||
{
|
||||
return $this->getRelations()->manyMany($params, $foreignParams);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*protected function belongsTo($params, $foreignParams)
|
||||
{
|
||||
return $this->getRelations()->belongsTo($params, $foreignParams);
|
||||
}
|
||||
|
||||
protected function hasMany($params, $foreignParams)
|
||||
{
|
||||
return $this->getRelations()->hasMany($params, $foreignParams);
|
||||
}
|
||||
|
||||
protected function hasChildren($params, $foreignParams)
|
||||
{
|
||||
return $this->getRelations()->hasChildren($params, $foreignParams);
|
||||
}
|
||||
|
||||
|
||||
/*protected function belongsToParent($params, $foreignParams)
|
||||
{
|
||||
return $this->getRelations()->belongsToParent($params, $foreignParams);
|
||||
}*/
|
||||
|
||||
protected function linkParent($params, $foreignParams)
|
||||
{
|
||||
return $this->getRelations()->linkParent($params, $foreignParams);
|
||||
}
|
||||
|
||||
protected function linkMultiple($params, $foreignParams)
|
||||
{
|
||||
return $this->getRelations()->linkMultiple($params, $foreignParams);
|
||||
}
|
||||
|
||||
|
||||
protected function teamRelation($params, $foreignParams)
|
||||
{
|
||||
return $this->getRelations()->teamRelation($params, $foreignParams);
|
||||
}
|
||||
} */
|
||||
|
||||
|
||||
|
||||
|
||||
/*protected function hasChildrenBelongsToParent()
|
||||
{
|
||||
return $this->getRelations()->hasChildren($params, $foreignParams);
|
||||
}*/
|
||||
|
||||
/*protected function hasManyBelongsTo($params, $foreignParams)
|
||||
{
|
||||
$hasMany = $this->getRelations()->hasMany($params, $foreignParams);
|
||||
$belongsTo = $this->getRelations()->belongsTo($foreignParams, $params);
|
||||
//$belongsTo [Contact] [relations] [account] ['foreignKey'] = 'id'; ???
|
||||
|
||||
return Util::merge($hasMany, $belongsTo);
|
||||
} */
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
[0] => belongsTo
|
||||
[1] => belongsToParent
|
||||
[2] => hasMany
|
||||
|
||||
@@ -181,8 +181,14 @@ class Orm
|
||||
|
||||
switch ($fieldParams['type']) {
|
||||
case 'linkParent':
|
||||
$relation = $this->getLinks()->process('linkParent', $entityName, array('name' => $fieldName));
|
||||
$outputMeta = Util::merge($outputMeta, $relation[$entityName]['fields']);
|
||||
$linkData = $this->getLinks()->process('linkParent', $entityName, array('name' => $fieldName));
|
||||
$outputMeta = Util::merge($outputMeta, $linkData[$entityName]['fields']);
|
||||
break;
|
||||
|
||||
case 'linkMultiple':
|
||||
$linkData = $this->getLinks()->process('linkMultiple', $entityName, array('name' => $fieldName));
|
||||
unset($outputMeta[$fieldName]); //no need "linkMultiple" field
|
||||
$outputMeta = Util::merge($outputMeta, $linkData[$entityName]['fields']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -278,9 +284,9 @@ class Orm
|
||||
} */
|
||||
|
||||
|
||||
if (method_exists($this->getLinks(), $method)) { //ex. hasManyHasMany
|
||||
if ( $this->getLinks()->isMethodExists($method) ) { //ex. hasManyHasMany
|
||||
$convertedLink = $this->getLinks()->process($method, $entityName, array('name'=>$linkName, 'params'=>$linkParams), $foreignLink);
|
||||
} else if (method_exists($this->getLinks(), $currentType)) { //ex. hasMany
|
||||
} else { //ex. hasMany
|
||||
$convertedLink = $this->getLinks()->process($currentType, $entityName, array('name'=>$linkName, 'params'=>$linkParams), $foreignLink);
|
||||
}
|
||||
|
||||
@@ -289,7 +295,10 @@ class Orm
|
||||
} */
|
||||
|
||||
//$relationships = Util::merge($relationships, $convertedLink);
|
||||
$relationships = Util::merge($convertedLink, $relationships);
|
||||
if ($convertedLink !== false) {
|
||||
$relationships = Util::merge($convertedLink, $relationships);
|
||||
}
|
||||
|
||||
|
||||
//echo $method.' = '.$currentType.' - '.$foreignLink['type'].'<br />';
|
||||
}
|
||||
|
||||
@@ -148,10 +148,6 @@ class Relations
|
||||
),
|
||||
);
|
||||
|
||||
/*if (isset($params['link']['params']['foreign'])) { //???
|
||||
$relation[$params['entityName']] ['fields'] [$params['link']['name'].'Name'] ['foreign'] = $params['link']['params']['foreign'];
|
||||
} */
|
||||
|
||||
return $relation;
|
||||
}
|
||||
|
||||
@@ -167,15 +163,13 @@ class Relations
|
||||
'foreignType' => $foreignParams['link']['name'].'Type', //???: 'foreignKey' => $params['link']['name'].'Id',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
return $relation;
|
||||
}
|
||||
|
||||
//uses for belongsToParent and linkParent
|
||||
//public function belongsToParent($params, $foreignParams)
|
||||
public function linkParent($params, $foreignParams)
|
||||
{
|
||||
$relation = array();
|
||||
@@ -202,6 +196,27 @@ class Relations
|
||||
return $relation;
|
||||
}
|
||||
|
||||
|
||||
public function linkMultiple($params, $foreignParams)
|
||||
{
|
||||
return array(
|
||||
$params['entityName'] => array (
|
||||
'fields' => array(
|
||||
$params['link']['name'].'Ids' => array(
|
||||
'type' => Entity::VARCHAR,
|
||||
'notStorable' => true,
|
||||
),
|
||||
$params['link']['name'].'Names' => array(
|
||||
'type' => Entity::VARCHAR,
|
||||
'notStorable' => true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function teamRelation($params, $foreignParams)
|
||||
{
|
||||
return array(
|
||||
|
||||
@@ -54,7 +54,7 @@ class Schema
|
||||
|
||||
//convertToSchema
|
||||
public function process(array $databaseMeta, $entityDefs)
|
||||
{
|
||||
{
|
||||
$schema = $this->getSchema();
|
||||
|
||||
$tables = array();
|
||||
@@ -125,6 +125,7 @@ class Schema
|
||||
$relationParams['midKeys'] = array_merge($relationParams['midKeys'], array_keys($relationParams['conditions']));
|
||||
}
|
||||
$tables[$tableName] = $this->prepareManyMany($entityName, $relationParams, $tables, false);
|
||||
//$table->addForeignKeyConstraint($tables['Team'], array($usMidKey), array($relationKey), array("onUpdate" => "CASCADE"));
|
||||
} else {
|
||||
$tables[$tableName] = $this->prepareManyMany($entityName, $relationParams, $tables);
|
||||
}
|
||||
|
||||
@@ -15,8 +15,5 @@
|
||||
"search":{
|
||||
"basic":false,
|
||||
"advanced":true
|
||||
},
|
||||
"database":{
|
||||
"skip":true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user