public function offsetSet($offset, $field) {

    // Allow you to set external id in the array offset.
    // E.g. $collection['external_id'] = $field;
    if (is_string($offset)) {
      $field->external_id = $offset;
      $offset = null;
    }

    if (!$field->id && !$field->external_id) {
      throw new PodioDataIntegrityError('Field must have id or external_id set.');
    }

    // Remove any existing field with this id
    $this->remove($field->id ? $field->id : $field->external_id);

    // Add to internal storage
    parent::offsetSet($offset, $field);
  }