Code Monkey home page Code Monkey logo

Comments (7)

Ocramius avatar Ocramius commented on June 15, 2024

@easy-cloud what does your entity look like? Because the identifier should always be there in an entity...

from doctrinemodule.

 avatar commented on June 15, 2024
        /**
         * @ORM\Id
         * @ORM\Column(type="integer",unique=true);
         * @ORM\GeneratedValue(strategy="AUTO")
        */
        protected $id;

this is my identifier, in all entities it is the same.

from doctrinemodule.

Ocramius avatar Ocramius commented on June 15, 2024

By looking at https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php#L645-677 it seems that your identifier is not set. Are you able to get a piece of code showing how you use the form?

from doctrinemodule.

 avatar commented on June 15, 2024
$this->add(array(
            'name' => 'location_id',
            'type' => 'DoctrineORMModule\Form\Element\DoctrineEntity',
            'options' => array(
                'label' => 'Location',
                'object_manager' => $em,
                'target_class'   => '\StadEnNatuur\Entity\Location',
                'property'       => 'name'
            ),
        ));

from doctrinemodule.

sergej-kurakin avatar sergej-kurakin commented on June 15, 2024

I'm experiencing same issue with Doctrine ORM/DBAL 2.3.0 and DoctrineModule/DoctrineORMModule (dev). It appears when I'm using associated entities:

User Entity

class User
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer", name="id")
     * @ORM\GeneratedValue
     */
    protected $id;
...
    /**
     * @ORM\OneToOne(targetEntity="Country")
     * @ORM\JoinColumn(name="country_id", referencedColumnName="id", nullable=true)
     */
    protected $country;
...

    /**
     * @return Application\Entity\Country
     */
    public function getCountry()
    {
        return $this->country;
    }
...
}

Country Entity

class Country
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer", name="id", nullable=false)
     * @ORM\GeneratedValue
     */
    protected $id;

    /**
     * @ORM\Column(type="string", name="name", nullable=true)
     */
    protected $name;
}

If I request Country associated with already requested User in database - getIdentifierValues returns empty array. For example (user 1 is associated with country 2):

$user = $entityManager->getRepository('Application\Entity\User')->find(1);
$country = $entityManager->getRepository('Application\Entity\Country')->find(2);
$metadata = $entityManager->getClassMetadata(get_class($country));
$countryId = $metadata->getIdentifierValues($country);
var_dump($countryId); // array(0) {}

Same result with getter:

$user = $entityManager->getRepository('Application\Entity\User')->find(1);
$country = $user ->getCountry();
$metadata = $entityManager->getClassMetadata(get_class($country));
$countryId = $metadata->getIdentifierValues($country);
var_dump($countryId); // array(0) {}

But if I request country that not associated with any requested entity it is OK (Country 1 not associated with any loaded User entities):

$country = $entityManager->getRepository('Application\Entity\Country')->find(1);
$metadata = $entityManager->getClassMetadata(get_class($country));
$countryId = $metadata->getIdentifierValues($country);
var_dump($countryId); // array(1) {["id"] => int(1)}

I've tried with one-to-one unidirectional association.

I think it must be checked on clean Doctrine ORM...

from doctrinemodule.

Ocramius avatar Ocramius commented on June 15, 2024

Closing as duplicate of #122

This will be fixed with Doctrine ORM 2.4

from doctrinemodule.

webdevilopers avatar webdevilopers commented on June 15, 2024

A question for @sergej-kurakin:
When using your example and adding my form element the way @easy-cloud did with location and I try to flush my entity I get the following error:

Catchable fatal error: Argument 1 passed to Application\Entity\Address::setCountry() must be an instance of Application\Entity\Country, string given

Entity and form seem to be correct. It looks like I am missing some kind of hydration to make ZF2 pass the object identifier instead of the posted form value. How did you manage this?

from doctrinemodule.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.