When I use PHP and the Propel ORM 2.0.0-dev to update a row in a table with the timestampable behavior, it always sets the created_at field as well as the updated_at field, which means that they're always the same. I want created_at to reflect when the row was created, not when it was last modified. Here's my code, what am I doing wrong?
$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:
<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>
Changing the code to not touch the primary key column when we're updating doesn't keep Propel from updating the created_at field:
$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();