public function saveRelation($instance, $types, $options = [])
    {
        $defaults = ['embed' => []];
        $options += $defaults;
        $types = (array) $types;

        $collection = $instance instanceof Document ? [$instance] : $instance;

        $success = true;
        foreach ($collection as $entity) {
            foreach ($types as $type) {
                foreach ($options['embed'] as $relName => $value) {
                    if (!($rel = $this->relation($relName)) || $rel->type() !== $type) {
                        continue;
                    }
                    $success = $success && $rel->save($entity,  $value ? $value + $options : $options);
                }
            }
        }
        return $success;
    }
public function saveRelation($instance, $types, $options = [])
    {
        $defaults = ['embed' => []];
        $options += $defaults;
        $types = (array) $types;

        $collection = $instance instanceof Document ? [$instance] : $instance;

        $success = true;
        foreach ($collection as $entity) {
            foreach ($types as $type) {
                foreach ($options['embed'] as $relName => $value) {
                    if (!($rel = $this->relation($relName)) || $rel->type() !== $type) {
                        continue;
                    }
                    $success = $success && $rel->save($entity,  $value ? $value + $options : $options);
                }
            }
        }
        return $success;
    }
public function saveRelation ( $ instance , $ types , $ options = [ ] ) { $ defaults = [ 'embed' => [ ] ] ; $ options += $ defaults ; $ types = ( array ) $ types ; $ collection = $ instance instanceof Document ? [ $ instance ] : $ instance ; $ success = true ; foreach ( $ collection as $ entity ) { foreach ( $ types as $ type ) { foreach ( $ options [ 'embed' ] as $ relName => $ value ) { if ( ! ( $ rel = $ this -> relation ( $ relName ) ) || $ rel -> type ( ) !== $ type ) { continue ; } $ success = $ success && $ rel -> save ( $ entity , $ value ? $ value + $ options : $ options ) ; } } } return $ success ; }
Save data related to relations.

@param  object  $instance The entity instance.
@param  array   $types    Type of relations to save.
@param  array   $options  Options array.
@return boolean           Returns `true` on a successful save operation, `false` on failure.
Save data related to relations .