Php Propel preSave()无法从数据库中获取记录

Php Propel preSave()无法从数据库中获取记录,php,orm,propel,Php,Orm,Propel,我正在构建一些网络应用程序。我不希望用户重写数据库中已经存在的值。我试图用preSave行为来检查这一点。每当我尝试从数据库中获取值时,我都会获取用户刚刚使用$\u POST[]发布的值 public function preSave(\PropelPDO $con = null) { $obj = new UserQuery(); //let's check if user has set the value $type = $obj->findOneById($

我正在构建一些网络应用程序。我不希望用户重写数据库中已经存在的值。我试图用preSave行为来检查这一点。每当我尝试从数据库中获取值时,我都会获取用户刚刚使用$\u POST[]发布的值

public function preSave(\PropelPDO $con = null) {
    $obj = new UserQuery();
    //let's check if user has set the value
    $type = $obj->findOneById($this->getId())->getType();
    var_dump($type);// <-- here the value from database is always as user 
                    //have just been selected in form. The value in database 
                    //actually is NULL

    //if type in database have been saved then set the current type from database 
    if(!is_null($type))
        $this->setType($type);

    return true;
}

所以我的问题是:为什么数据库中的值从不为NULL,而是用户在表单中选择的一些真或假?它应该是空的,因为在那一刻还没有执行save。

我想,您得到相同的对象是因为。它只是缓存以前获取的对象。因此,您可以尝试禁用preSave方法的实例池:

public function preSave(\PropelPDO $con = null) {
    \Propel::disableInstancePooling();
    // your code...
    \Propel::enableInstancePooling();
}