src/Model.php
protected function save_has_foreign_relations() {

		foreach ( $this->_relations as $attribute => $value ) {
			$relation = $this->get_relation( $attribute );

			if ( $relation instanceof HasForeign && $value ) {

				$value = $relation->persist( $value );
				$pk    = $relation->get_pk_for_value( $value );

				$this->set_raw_attribute( $attribute, $pk );
				$this->_relations[ $attribute ] = $value;
			}
		}
	}
protected function save_has_foreign_relations() {

		foreach ( $this->_relations as $attribute => $value ) {
			$relation = $this->get_relation( $attribute );

			if ( $relation instanceof HasForeign && $value ) {

				$value = $relation->persist( $value );
				$pk    = $relation->get_pk_for_value( $value );

				$this->set_raw_attribute( $attribute, $pk );
				$this->_relations[ $attribute ] = $value;
			}
		}
	}
Save the has foreign relations.

These need to be saved early because otherwise they will be persisted to both
the attribute value cache, and the relation cache.

@since 2.0