当我使用PHP和Propel ORM 2.0.0-dev更新具有时间戳行为的表中的行时,它总是设置created_at字段以及updated_at字段,这意味着它们总是相同的。我希望created_at能够反映创建行的时间,而不是上次修改时的行。这是我的代码,我做错了什么?
$person = PeopleQuery::create()->findOneByUserid($vals->userid);
if (is_null($person)) $person = new People();
$person->setUserid($vals->userid);
$person->setAddress($vals->address);
$person->setCity($vals->city);
$person->setState($vals->state);
$person->setZip($vals->zip);
$person->setCountry($vals->country);
$person->setClientIP($vals->clientIP);
$person->save();
表:
<table name="people" idMethod="native" phpName="People">
<column name="userid" phpName="Userid" type="INTEGER" primaryKey="true" required="true"/>
<column name="address" phpName="Address" type="VARCHAR" required="true"/>
<column name="city" phpName="City" type="VARCHAR" required="true"/>
<column name="state" phpName="State" type="VARCHAR" required="true"/>
<column name="zip" phpName="Zip" type="VARCHAR" required="true"/>
<column name="country" phpName="Country" type="VARCHAR" required="true"/>
<column name="clientIP" phpName="ClientIP" type="VARCHAR"/>
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
</vendor>
<behavior name="timestampable" />
</table>
在我们更新时将代码更改为不接触主键列不会使Propel无法更新created_at字段:
$person = PeopleQuery::create()->findOneByUserid($vals->userid); // so that it does both inserts and updates
if (is_null($person)) {
$person = new People();
$person->setUserid($vals->userid);
echo '<p>Did NOT find person</p>';
} else {
echo '<p>Found person</p>';
}
$person->setAddress($vals->address);
$person->setCity($vals->city);
$person->setState($vals->state);
$person->setZip($vals->zip);
$person->setCountry($vals->country);
$person->setClientIP($vals->clientIP);
$person->save();