0

I have a form that submits data to my controller. The function createAction() takes care for adding a new record to the database.

I need to get a certain value (specialValue) from the previous record in the database, which is neither deleted nor hidden. However, with the following, I can only get the uid (not respecting the deleted/hidden state).

public function createAction(Tx_MyExt_Domain_Model_MyObject $myobject) {
    $this->myObjectRepository->add($myobject);

    $persistenceManager = t3lib_div::makeInstance('Tx_Extbase_Persistence_Manager');        
    $persistenceManager->persistAll();

    $uid = $myobject->getUid();
    $previousMyObject = $this->myObjectRepository->findByUid($uid-1);
    $myobject->setSpecialValue($previousMyObject->getSpecialValue() +1);
}

Is there something like a findPrevious() method for my repository, or do I have to create it myself?

4

1 回答 1

1

使用降序排序,使用少于新对象(在您的情况下)获取第一个可用(未隐藏,未删除)对象,将其添加到您的存储库中:uid$uid

public function findPreviousAvailable($uid) {
    $query = $this->createQuery()
        ->setOrderings(array('uid'=> Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING));

    $query->matching($query->lessThan('uid', $uid));

    return $query->execute()->getFirst();
}

除非您不强制忽略启用的字段,否则它们将包含在查询中(还有用户组、访问时间等)

而且......不,afaik没有开箱即用的这种方法。

于 2013-06-18T16:08:53.090 回答