0
votes

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.

1
Do you want to force extendMomentoLock to always update the table, even when LOCKED & LOCKEDBY are the same from previous version, right?j0k
Yes @j0k you are right. Currently I'm doing it with a heck like created one new column and incrementing it to ensure updated_at changes which, I know, is a bad solution. Ideal solution is to update updated_at column regardless of other column change or not.Kapil Sharma
I guess you're using the Timestampable behavior so it will update date fields only if change are perfom on the row. Have you tried to explicitly add the updated_at column in $updatec ?j0k
@j0k Somehow Netbeans didn't populated setUpdatedAt() method while I was trying it last week. I cross-checked it again and found its available in BaseMomento.php. I'll try that once and get back again.Kapil Sharma
Why not just add $updatec->addAnd(MomentoPeer::UPDATED_AT, 'NOW()'); ?j0k

1 Answers

1
votes

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()');