Search code examples
symfony-1.4propel

Enforce 'updated_at' column change with Symfony/Propel 1.4


I've an existing project in Symfony 1.4 and Propel 1.4

For a new requirement, I tried following code:

static public function extendMomentoLock($momentoId,$memberId)
{
    $wherec = new Criteria();
    $updatec = new Criteria();

    $updatec->add(MomentoPeer::LOCKED, 1);
    $updatec->addAnd(MomentoPeer::LOCKEDBY, $memberId);
    $wherec->add(MomentoPeer::ID, $momentoId, Criteria::EQUAL);

    $con = Propel::getConnection(MemberPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
    BasePeer::doUpdate($wherec, $updatec, $con);

    return "extended";
}

As expected, it generated correct query, as taken from logs

UPDATE momento SET `LOCKED`=1, `LOCKEDBY`=6 WHERE momento.ID='198'

No issue till here.

Problem starts, as I need to run this query every 3 minutes. Rule is, row gets unlocked automatically every 5 minutes, if record is updated 5 minutes earlier. To keep it locked, updated_at column must be less then 5 minutes so browser sends request to keep record locked.

I was expecting query to update updated_at column. However, since nothing is updating in query, updated_at column is not updating.

Is there any way to force propel to execute query, even when no records are updated.


Solution

  • I guess you're using the Timestampable behavior so it will update date fields only if changes are perform on the row.

    I think you can force the update using a basic SQL statement:

    $updatec->addAnd(MomentoPeer::UPDATED_AT, 'NOW()');