public function offsetSet($offset, $value) {
    if (!is_a($value, 'PodioObject')) {
      throw new PodioDataIntegrityError("Objects in PodioCollection must be of class PodioObject");
    }

    // If the collection has a relationship with a parent, add it to the item as well.
    $relationship = $this->relationship();
    if ($relationship) {
      $value->add_relationship($relationship['instance'], $relationship['property']);
    }

    if (is_null($offset)) {
      $this->__items[] = $value;
    }
    else {
      $this->__items[$offset] = $value;
    }
  }