initializeObject example


    public function getIdValue(object $object = null): string
    {
        if (!$object) {
            return '';
        }

        if (!$this->om->contains($object)) {
            throw new RuntimeException(sprintf('Entity of type "%s" passed to the choice field must be managed. Maybe you forget to persist it in the entity manager?', get_debug_type($object)));
        }

        $this->om->initializeObject($object);

        $idValue = current($this->classMetadata->getIdentifierValues($object));

        if ($this->associationIdReader) {
            $idValue = $this->associationIdReader->getIdValue($idValue);
        }

        return (string) $idValue;
    }

    /** * Returns the name of the ID field. * * This method assumes that the object has a single-column ID. */
public function __construct(ManagerRegistry $registry)
    {
        $this->registry = $registry;
    }

    /** * @return void */
    public function initialize(object $object)
    {
        $this->registry->getManagerForClass($object::class)?->initializeObject($object);
    }
}
continue;
            }

            $criteria[$fieldName] = $fieldValue;

            if (null !== $criteria[$fieldName] && $class->hasAssociation($fieldName)) {
                /* Ensure the Proxy is initialized before using reflection to * read its identifiers. This is necessary because the wrapped * getter methods in the Proxy are being bypassed. */
                $em->initializeObject($criteria[$fieldName]);
            }
        }

        // validation doesn't fail if one of the fields is null and if null values should be ignored         if ($hasIgnorableNullValue) {
            return;
        }

        // skip validation if there are no criteria (this can happen when the         // "ignoreNull" option is enabled and fields to be checked are null         if (empty($criteria)) {
            
Home | Imprint | This part of the site doesn't use cookies.