。
我正在挠头。我有下表:
<table name="activity" idMethod="native" phpName="Activity">
<column name="id" phpName="Id" type="INTEGER" size="13" primaryKey="true" autoIncrement="true" required="true"/>
<column name="created" phpName="Created" type="TIMESTAMP" required="true" defaultExpr="CURRENT_TIMESTAMP"/>
<column name="modified" phpName="Modified" type="TIMESTAMP" required="true" defaultExpr="CURRENT_TIMESTAMP"/>
<column name="provider_id" phpName="ProviderId" type="INTEGER" size="13" required="true"/>
<column name="name" phpName="Name" type="VARCHAR" size="100" required="true"/>
<column name="description" phpName="Description" type="LONGVARCHAR"/>
<column name="grade_min" phpName="GradeMin" type="INTEGER" size="2" required="true" defaultValue="0"/>
<column name="grade_max" phpName="GradeMax" type="INTEGER" size="2" required="true" defaultValue="12"/>
<column name="duration" phpName="Duration" type="INTEGER" size="3" required="true" defaultValue="60"/>
<column name="image" phpName="Image" type="VARCHAR" size="255" required="true" defaultValue=""/>
<column name="webpage" phpName="Webpage" type="VARCHAR" size="255" required="true" defaultValue=""/>
<column name="approved" phpName="Approved" type="CHAR" sqlType="enum('Y','N')" required="true" defaultValue="N"/>
<foreign-key foreignTable="provider" name="activity_provider" onUpdate="CASCADE">
<reference local="provider_id" foreign="id"/>
</foreign-key>
<unique name="provider_name">
<unique-column name="provider_id"/>
<unique-column name="name"/>
</unique>
<vendor type="mysql">
<parameter name="Engine" value="InnoDB"/>
</vendor>
</table>
我执行以下php:
$approved = $activity->getApproved();
if($approved == "N"){
$activity->setApproved("Y"); // verified this line is executing
} else {
$activity->setApproved("N");
}
echo $activity->getApproved(); // this outputs "Y"
$activity->save(); // produces line in the query log
die($activity->getApproved()); // this outputs "N"
从save()
方法中的查询日志中产生了一条线:
[2018-02-26T17:00:09.038703-08:00] default.INFO: UPDATE activity SET approved='N' WHERE activity.id=6 [] []
当approved
字段设置为Y
时,同一查询运行并成功(该字段已切换到N
(。有什么想法在这里发生什么?Propel2讨厌枚举吗?有任何建议解决此问题的建议吗?
对不起,我发现了我遇到的问题的原因。我在Activity
型号上有一个preSave
挂钩,该挂钩的集合在保存时批准为"N"
。目的是,如果更改活动,它将失去其批准的状态,但是由于储蓄发生在setApproved("Y")
之后,因此挂钩会发射并将其设置为"N"
。我通过检测是否正在修改Approved
列,并仅将Approved
列设置为"N"
,请修复它。