5

I have to update multiple columns in Symfony, but I can nowhere find the solution... So, I'd like to do it in this way:

$q = Doctrine_Query::create()
     ->update('WebusersTable q')
     ->set('q.login_name','?','John')
     ->where('q.webuser_id=?',1)
     ->execute();

OK, that works, but I have to do it with several columns. I tried something like this, but it doesn't work:

$q = Doctrine_Query::create()
     ->update('WebusersTable q')
     ->set('q.login_name,q.name','?','kaka,pisa')
     ->where('q.webuser_id=?',1)
     ->execute();
BenV
  • 12,052
  • 13
  • 64
  • 92
kungfucsiga
  • 329
  • 1
  • 4
  • 13

3 Answers3

14

Try:

$q = Doctrine_Query::create()
     ->update('WebusersTable q')
     ->set('q.login_name', 'John')
     ->set('q.name', 'Another value')
     ->where('q.webuser_id=?',1)
     ->execute();
Darmen Amanbay
  • 4,869
  • 3
  • 29
  • 50
  • Neat - not seen that used before. +1 :) – richsage Jan 26 '11 at 10:47
  • 1
    How does jQuery know John is a literal, not a colum name (I am asking because there are samples like ->set('amount','amount + 200'). And I do have problems along these lines... – Frank N Nov 25 '11 at 11:57
  • @Fronker as of Doctrine_Query_Abstract at line 1626 `return $this->_addDqlQueryPart('set', $key . ' = ' . $value, true);` it does not check here. It checks right before generating complete raw SQL with regex and components. You wouldn't have any problems. – Darmen Amanbay Nov 25 '11 at 12:48
1

Try

$q = Doctrine_Query::create()
->update('WebusersTable q')
->set(array('q.login_name' => 'John',
            'q.name' => 'Another value'))
->where('q.webuser_id=?',1)
->execute();
Michail M.
  • 735
  • 5
  • 11
0
class contentActions extends sfActions {

const TABLE_NAME_ARTICLE = 'article';

/**
 * Executes index action
 *
 * @param sfRequest $request A request object
 */
public function executeIndex(sfWebRequest $request) {


    // Get id from $_GET
    $id = $request->hasParameter('id') ? $request->getParameter('id') : $request->getPostParameter(self::TABLE_NAME_ARTICLE . '[id]');

    // Create model active row by id
    $modelActiveRow = Doctrine::getTable(self::TABLE_NAME_ARTICLE)->find($id);

    // Verify existence article
    $this->forward404Unless($modelActiveRow);

    // Get form name
    $formName = self::TABLE_NAME_ARTICLE . 'Form';

    // Create article form object. Use model article (load data).
    $this->form = new $formName($modelActiveRow);

    if ($request->isMethod('post')) {

        $postData = $request->getParameter(self::TABLE_NAME_ARTICLE);
        $this->form->bind($postData);

        if ($this->form->isValid()) {
            $this->form->save();
            $this->getUser()->setFlash('notice', 'Changes were successfully saved.');
            // redirect
        }
    }

}

}

n1ckolas
  • 4,380
  • 3
  • 37
  • 43
Patrik
  • 1