mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-07-01 05:55:02 +03:00
Обновление many-to-many
This commit is contained in:
parent
4233f8a709
commit
9d321e1ad2
|
@ -415,5 +415,12 @@ abstract class EntityORM extends Entity {
|
|||
return $this->$sName;
|
||||
}
|
||||
}
|
||||
|
||||
public function resetRelationsData($sKey)
|
||||
{
|
||||
if (isset($this->aRelationsData[$sKey])) {
|
||||
unset($this->aRelationsData[$sKey]);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -10,10 +10,11 @@ class LS_ManyToManyRelation
|
|||
// Ссылка на $oEntityORM->aRelationsData[<relation_name>],
|
||||
// где relation_name - имя сязи, которую представляет объект
|
||||
protected $_aCollection = array();
|
||||
protected $bUpdated = false;
|
||||
|
||||
public function __construct(&$aCollection)
|
||||
public function __construct($aCollection)
|
||||
{
|
||||
$this->_aCollection = &$aCollection;
|
||||
$this->_aCollection = $aCollection;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,6 +23,7 @@ class LS_ManyToManyRelation
|
|||
*/
|
||||
public function add($oEntity)
|
||||
{
|
||||
$this->bUpdated = true;
|
||||
$this->_aCollection[$oEntity->_getPrimaryKeyValue()] = $oEntity;
|
||||
}
|
||||
|
||||
|
@ -31,6 +33,7 @@ class LS_ManyToManyRelation
|
|||
*/
|
||||
public function delete($iId)
|
||||
{
|
||||
$this->bUpdated = true;
|
||||
if (is_array($iId)) {
|
||||
foreach ($iId as $id) {
|
||||
if (isset($this->_aCollection[$id])) {
|
||||
|
@ -41,6 +44,16 @@ class LS_ManyToManyRelation
|
|||
unset($this->_aCollection[$iId]);
|
||||
}
|
||||
}
|
||||
|
||||
public function getCollection()
|
||||
{
|
||||
return $this->_aCollection;
|
||||
}
|
||||
|
||||
public function isUpdated()
|
||||
{
|
||||
return $this->bUpdated;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -143,8 +143,8 @@ class MapperORM extends Mapper {
|
|||
|
||||
list($aFilterFields,$sFilterFields)=$this->BuildFilter($aFilter,$oEntitySample);
|
||||
|
||||
$sql = "SELECT count(*) as c FROM ?# a LEFT JOIN ".$sTableName." b ON b.?# = a.?# WHERE a.?#=? {$sFilterFields}";
|
||||
$aQueryParams=array_merge(array($sql,$aFilter['#join_table'],$sPrimaryKey,$aFilter['#relation_key'],$aFilter['#by_key'],$aFilter['#by_value']),array_values($aFilterFields));
|
||||
$sql = "SELECT count(*) as c FROM ?# a WHERE a.?#=? {$sFilterFields}";
|
||||
$aQueryParams=array_merge(array($sql,$aFilter['#join_table'],$aFilter['#by_key'],$aFilter['#by_value']),array_values($aFilterFields));
|
||||
|
||||
if($aRow=call_user_func_array(array($this->oDb,'selectRow'),$aQueryParams)) {
|
||||
return $aRow['c'];
|
||||
|
|
|
@ -48,11 +48,11 @@ abstract class ModuleORM extends Module {
|
|||
// Обновление связей many_to_many
|
||||
$aRelationsData = $oEntity->_getRelationsData();
|
||||
foreach ($oEntity->_getRelations() as $sRelName => $aRelation) {
|
||||
if ($aRelation[0] == EntityORM::RELATION_TYPE_MANY_TO_MANY && isset($aRelationsData[$sRelName])) {
|
||||
if ($aRelation[0] == EntityORM::RELATION_TYPE_MANY_TO_MANY && $oEntity->$sRelName->isUpdated()) {
|
||||
// Сброс кэша по связям
|
||||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array('m2m_'.$aRelation[2].$aRelation[4].$oEntity->_getPrimaryKeyValue()));
|
||||
|
||||
$this->_updateManyToManySet($aRelation, $aRelationsData[$sRelName], $oEntity->_getDataOne($oEntity->_getPrimaryKey()));
|
||||
$this->_updateManyToManySet($aRelation, $oEntity->$sRelName->getCollection(), $oEntity->_getDataOne($oEntity->_getPrimaryKey()));
|
||||
$oEntity->resetRelationsData($sRelName);
|
||||
}
|
||||
}
|
||||
return $oEntity;
|
||||
|
@ -67,10 +67,12 @@ abstract class ModuleORM extends Module {
|
|||
// Обновление связей many_to_many
|
||||
$aRelationsData = $oEntity->_getRelationsData();
|
||||
foreach ($oEntity->_getRelations() as $sRelName => $aRelation) {
|
||||
if ($aRelation[0] == EntityORM::RELATION_TYPE_MANY_TO_MANY && isset($aRelationsData[$sRelName])) {
|
||||
if ($aRelation[0] == EntityORM::RELATION_TYPE_MANY_TO_MANY && $oEntity->$sRelName->isUpdated()) {
|
||||
// Сброс кэша по связям
|
||||
|
||||
$this->Cache_Clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG,array('m2m_'.$aRelation[2].$aRelation[4].$oEntity->_getPrimaryKeyValue()));
|
||||
$this->_updateManyToManySet($aRelation, $aRelationsData[$sRelName], $oEntity->_getDataOne($oEntity->_getPrimaryKey()));
|
||||
$this->_updateManyToManySet($aRelation, $oEntity->$sRelName->getCollection(), $oEntity->_getDataOne($oEntity->_getPrimaryKey()));
|
||||
$oEntity->resetRelationsData($sRelName);
|
||||
}
|
||||
}
|
||||
// сбрасываем кеш
|
||||
|
|
Loading…
Reference in a new issue