Two problems prevented me from performing updates to existing records in a table:

1. dbtng does not automatically set 'all_fields' unless $select->fields() is executed on the select object.
2. Keys are never populated, so db_write_record() always does an INSERT

      $select = db_select($this->tableName);
      // Below is needed; otherwise 'SELECT FROM' is sent, which results in an SQL error
      $select->fields($this->tableName, array());
      foreach ($this->schema['primary key'] as $key) {
        $select->condition($key, $entity->{$key});
        // Below is needed; otherwise $primary_key is left empty, leading db_write_record to perform
        // an insert.
        $primary_key[] = $key;
      }

So, either I'm missing something, or this is a bug. I'm happy to roll a patch if this seems right.

Comments

mikeryan’s picture

Status: Active » Fixed

It was close - --update failed regardless of systemOfRecord, so I moved the setting of $primary_key up to the migrate_map_destid1 case and that does the trick.

Thanks!

cmjns’s picture

Is there a patch for that? Did you roll it into dev?

mikeryan’s picture

I committed it to git, so it is automatically incorporated into -dev.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.