1

I work with views bulk operations and I wanna change status of selected items in a view. I applied db_update query, but something went wrong. I was debugging my code following:

  $status=$context['status'];


foreach($context['rows'] as $order) {

    db_update('orders')
        ->fields(array(
            'status' => $status
        ))
        ->condition('oid',$order->oid,'=')
        ->execute();
}



foreach($context['rows'] as $order) {
    $result = db_select('orders','status')
        ->fields('status')
        ->condition('oid',$order->oid)
        ->execute()
        ->fetchAssoc();
    if($result) {
        drupal_set_message($result['status']);
        drupal_set_message($result['oid']);
    }
}

So first is db_update and after that I did db_select and printed it out.The result of this db_select behaves like status would be updated. But in the node is status still the same. Also in database it stayed unchanged. I have no idea what's wrong. It behaves like it was updated and then immediately got back.I would be very helpful for any help. Sorry for my english. Thanks.

0

My first inclination is that this is a caching issue.

Other possibilities:

  • Is the node actually stored in the orders table? Do you do the appropriate updates for the nodes table as well?
  • Is this in an incomplete transaction? (db_transaction)
  • Have you checked the return value of the ->execute() to see if it is returning the right number of rows?

Without a full description of what the variable $context and the table orders contains, it is hard to give any better answers.

  • No. The node is not stored in orders table. I update just order's field status. The return value of execute() is always 1 for every update I do in a foreach loop. Context variabe is fine. I dumped all variables and they are correct. If they wouldn's the select query does not work properly. – user3396700 Apr 1 '15 at 16:36
  • If I look into database, I can see via date of last change, that these rows I wanted to update were changed after my query is executed. – user3396700 Apr 1 '15 at 16:39
  • If the rows were updated, but new info is not displayed, then it has to be a caching issue. If they were updated and then changed back, then you have something else overriding your changes. – Kevin Finkenbinder Apr 1 '15 at 20:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.