2010-03-22 71 views

回答

3

我敢肯定,学说(至少1.2版本)版本化行为没有按除revert()之外,不为您的模型定义任何其他方法,允许您恢复以前版本的资源。

所以你必须自己做一切。

+0

是啊,这就是我的想法。尽管感谢您的帮助。 – jjbohn 2010-03-23 17:33:42

+0

我在下面张贴了另一种方式。你认为这是Symfony的具体情况,并不是在纯粹的教义中可用? – Tapper 2012-07-18 09:45:41

1

您可以在版本表上查询: Doctrine :: getTable('EntityVersions') - > findAllById($ entity_id);

gyaan:对于任何版本表,PK共同放置在版本号&版本上。不像默认的教条样式,没有代理键!

0

只是为了防止其他人绊倒在这:这是一个快速解决方案如何获取版本化的记录。 (这当然应该更好地进行内部或作为“审计日志”类的扩展实现,但对于一个快速的解决方案下面可以去任何地方。)

/** 
* get collection of versioned records as array 
* 
* @param string $table table name without the 'Version' -suffix (e.g. 'User' instead of 'UserVersion') 
* @param mixed $id simple id or array with key/value pairs for compound keys 
* @return array 
*/ 
public function getHistory($table, $ids) { 

    $className = $table . 'Version'; 

    $identifiers = (array) Doctrine_Core::getTable($table)->getIdentifier(); 
    if (count($identifiers) === 1) { 
     $ids = array_combine($identifiers, (array) $ids); 
    } 

    $q = Doctrine_Core::getTable($className) 
      ->createQuery(); 

    $conditions = array(); 
    $values = array(); 
    foreach ($identifiers as $id) { 
     if (!isset($ids[$id])) { 
      throw new Doctrine_Record_Exception('Primary key \'' . $id . '\' must be given to access ' . $className . '.'); 
     } 
     $conditions[] = $className . '.' . $id . ' = ?'; 
     $values[] = $ids[$id]; 
    } 

    $q->where(implode(' AND ', $conditions)); 

    $data = $q->execute($values, Doctrine_Core::HYDRATE_ARRAY); 

    return $data; 
} 
1

我在相应表-1实施的访问捷径类例如model/doctrine/ItemTable.class.php

public static function getHistoryInstance() { 
    return self::getInstance()->getTemplate('Versionable')->getAuditLog()->getTable(); 
} 

然后从徘徊无论访问历史是这样的:

$history_collection = ItemTable::getHistoryInstance()->createQuery() 
      ->select('id') 
      ->execute(); 

(我使用的Symfony 1.4学说1.2)

相关问题