/**
  * {@inheritdoc}
  */
 public function buildClearRelatedObjectsMethod(StructureInterface $structure, TypeInterface $source_type, TypeInterface $target_type, $namespace, array &$result)
 {
     $intermediary_type = $structure->getType($this->intermediary_type_name);
     $intermediary_instance_class = $this->getInstanceClassFrom($namespace, $intermediary_type);
     $result[] = '';
     $result[] = '    /**';
     $result[] = '     * Drop all connections between ' . str_replace('_', ' ', $target_type->getName()) . ' and this ' . Inflector::singularize($source_type->getName()) . '.';
     $result[] = '     *';
     $result[] = '     * @return $this';
     $result[] = '     */';
     $result[] = "    public function &clear{$this->getClassifiedAssociationName()}()";
     $result[] = '    {';
     $result[] = '        if ($objects = $this->get' . $this->getClassifiedAssociationName() . '()) {';
     $result[] = '            $object_ids = [];';
     $result[] = '';
     $result[] = '            $this->connection->transact(function () use ($objects, &$object_ids) {';
     $result[] = '                foreach ($objects as $object) {';
     $result[] = '                    $object_ids[] = $object->getId();';
     $result[] = '                    $object->delete(true);';
     $result[] = '                }';
     $result[] = '            });';
     $result[] = '';
     $result[] = '            $this->pool->forget(' . var_export($intermediary_instance_class, true) . ', $object_ids);';
     $result[] = '        }';
     $result[] = '';
     $result[] = '        return $this;';
     $result[] = '    }';
 }