Prepare has one constraint statement.

@param  TypeInterface     $type
@param  HasOneAssociation $association
@return string
964030
public function prepareHasOneConstraintStatement(TypeInterface $type, HasOneAssociation $association)
    {
        $result = [];

        $result[] = 'ALTER TABLE ' . $this->getConnection()->escapeTableName($type->getName());
        $result[] = '    ADD CONSTRAINT ' . $this->getConnection()->escapeFieldName($association->getConstraintName());
        $result[] = '    FOREIGN KEY (' . $this->getConnection()->escapeFieldName($association->getFieldName()) . ') REFERENCES ' . $this->getConnection()->escapeTableName($association->getTargetTypeName()) . '(`id`)';

        if ($association->isRequired()) {
            $result[] = '    ON UPDATE CASCADE ON DELETE CASCADE;';
        } else {
            $result[] = '    ON UPDATE SET NULL ON DELETE SET NULL;';
        }

        return implode("\n", $result);
    }
744805
public function get(Connection $connection, string $type): ConstraintInterface
    {
        $driver = $connection->driver();

        if (isset($this->instances[$driver][$type])) {
            return $this->instances[$driver][$type];
        }

        return $this->instances[$driver][$type] = $this->createInstance($connection, $type);
    }
196193
public function has($expression, $type = Query::TYPE_CSS)
    {
        return $this->toDocument()->has($expression, $type);
    }
927462
public function associate(Association $association, Entry $entry, $input)
    {
        if ($association instanceof ManyToOneAssociation) {
            return $this->associateManyToOne($association, $entry, $input);
        }
        if ($association instanceof OneToOneAssociation) {
            return $this->associateOneToOne($association, $entry, $input);
        }
        if ($association instanceof OneToManyAssociation) {
            return $this->associateOneToMany($association, $entry, $input);
        }
        if ($association instanceof ManyToManyAssociation) {
            return $this->associateManyToMany($association, $entry, $input);
        }
    }
1126879
private function isParentModuleAssociation(Association $association) : bool
    {
        return in_array($this->getModelByAssociation($association), $this->getParentModules());
    }
1363580
public function resolve(Constraint $constraint, FormInterface $form, RuleCollection $collection)
    {
        $constraintClass = get_class($constraint);

        /** @var \Symfony\Component\Validator\Constraints\AbstractComparison $constraint */
        if ($constraintClass === GreaterThan::class) {
            $rule = new ConstraintRule(
                self::RULE_NAME,
                $constraint->value + 1, // TODO support floats
                new RuleMessage($constraint->message, array('{{ compared_value }}' => $constraint->value)),
                $constraint->groups
            );
        } elseif ($constraintClass === GreaterThanOrEqual::class) {
            $rule = new ConstraintRule(
                self::RULE_NAME,
                $constraint->value,
                new RuleMessage($constraint->message, array('{{ compared_value }}' => $constraint->value)),
                $constraint->groups
            );
        }
        /** @var Range $constraint */
        elseif ($constraintClass === Range::class && $constraint->min !== null) {
            $rule = new ConstraintRule(
                self::RULE_NAME,
                $constraint->min,
                new RuleMessage($constraint->minMessage, array('{{ limit }}' => $constraint->min)),
                $constraint->groups
            );
        } else {
            throw new LogicException();
        }

        $collection->set(
            self::RULE_NAME,
            $rule
        );
    }
166285
private function associationsMerege($name,$association) {
		$name= Inflector::tableize($name);
		if (!isset($this->models[$name])){
			$this->models[$name] = array();
		}
		if(!isset($association[0])) {
			$association = array($association);
		}
		
		
		foreach($association as $key => $rec) {
			
			if($rec['id'] !== null && !Hash::contains($this->models[$name], $rec) ) {
				$this->models[$name][] =  $rec;
			}
		}
	}
843032
def has_one(*args, &extension)
      options = args.extract_options! || {}
      if VALID_DEPENDENTS.include?(options[:dependent].try(:to_sym))
        reflection = if active_record_4?
          association_id, scope = *args
          restrict_create_reflection(:has_one, association_id, scope || {}, options, self)
        else
          association_id = args[0]
          create_reflection(:has_one, association_id, options, self)
        end
        add_dependency_callback!(reflection, options)
      end
      args << options
      super(*args, &extension)
    end
891282
private function getParentJoin(Association $association): array
    {
        $table = $association->getTarget();

        $result = [];
        foreach (Utils::getTableAssignationFields($table) as $field) {
            $result[$table->aliasField($field) . ' IN'] = $this->user['id'];
        }

        return $result;
    }
534262
private function getMapping(TypeInterface $type)
    {
        $type = (string) $type->getType();

        if (!isset($this->mappings[$type])) {
            throw new \InvalidArgumentException(sprintf('The mapping for type "%s" could not be found.', $type));
        }

        return $this->mappings[$type];
    }
295759
public function visitAssociation($className, $association = null)
    {
        if (null === $association) {
            return $this->visitSingleSidedAssociation($className);
        }

        return $this->visitDoubleSidedAssociation($className, $association);
    }
144977
private static function configureClauses(array $where, $type = 'and')
    {
        if ( ! in_array($type, ['and', 'or'])) {
            throw new \InvalidArgumentException('where-type must be `and` or `or`');
        }
        $whereClauses = [];
        foreach ($where as $name => $value) {
            $nameAndOp = explode(' ', $name, 2);
            $name      = $nameAndOp[0];
            $operator  = $nameAndOp[1] ?? ($value === null ? 'is' : '=');
            $alias     = self::cutAlias($name);

            $whereClauses[] = [$name, $value, $operator, $alias];
        }

        return [$type => $whereClauses];
    }
624991
public function joinRelations($relations, $type = 'inner')
    {
        if (is_null($this->joiner)) {
            $this->joiner = static::$joinerFactory->make($this);
        }

        if (!is_array($relations)) {
            list($relations, $type) = [func_get_args(), 'inner'];
        }

        foreach ($relations as $relation) {
            $this->joiner->join($relation, $type);
        }

        return $this;
    }
522059
protected function getJoinSQLForAssociation(AssociationMetadata $association)
    {
        if (! $association->isOwningSide()) {
            return 'LEFT JOIN';
        }

        // if one of the join columns is nullable, return left join
        foreach ($association->getJoinColumns() as $joinColumn) {
            if (! $joinColumn->isNullable()) {
                continue;
            }

            return 'LEFT JOIN';
        }

        return 'INNER JOIN';
    }
199136
private function resolveType(FormTypeInterface $type)
    {
        $typeExtensions = [];
        $parentType = $type->getParent();
        $fqcn = \get_class($type);

        if (isset($this->checkedTypes[$fqcn])) {
            $types = implode(' > ', array_merge(array_keys($this->checkedTypes), [$fqcn]));
            throw new LogicException(sprintf('Circular reference detected for form type "%s" (%s).', $fqcn, $types));
        }

        $this->checkedTypes[$fqcn] = true;

        try {
            foreach ($this->extensions as $extension) {
                $typeExtensions = array_merge(
                    $typeExtensions,
                    $extension->getTypeExtensions($fqcn)
                );
            }

            return $this->resolvedTypeFactory->createResolvedType(
                $type,
                $typeExtensions,
                $parentType ? $this->getType($parentType) : null
            );
        } finally {
            unset($this->checkedTypes[$fqcn]);
        }
    }
767730
public static function newEntityFoundThroughRelationship(AssociationMetadata $association, $entry)
    {
        $message = "A new entity was found through the relationship '%s#%s' that was not configured to cascade "
            . 'persist operations for entity: %s. To solve this issue: Either explicitly call EntityManager#persist() '
            . 'on this unknown entity or configure cascade persist this association in the mapping for example '
            . '@ManyToOne(..,cascade={"persist"}).%s';

        $messageAppend = method_exists($entry, '__toString')
            ? ''
            : " If you cannot find out which entity causes the problem implement '%s#__toString()' to get a clue.";

        return new self(sprintf(
            $message,
            $association->getSourceEntity(),
            $association->getName(),
            self::objToStr($entry),
            sprintf($messageAppend, $association->getTargetEntity())
        ));
    }
1128457
protected function hasOne($associatedClass, $foreignKey = null, $mappingKeyInBaseTable = null)
    {
        return $this->findHasOneOrMany($associatedClass, $foreignKey, $mappingKeyInBaseTable);
    }