Code Monkey home page Code Monkey logo

Comments (3)

Ocramius avatar Ocramius commented on June 15, 2024

Weird... I think this may be a case that is not handled. What happens if you add a default @Id @GeneratedValue(strategy="AUTO") and make your email just a column?

from doctrinemodule.

alexshelkov avatar alexshelkov commented on June 15, 2024

I use MongoDB ODM (and doctrine-mongo-odm-module), I think that in that case it not important, but may be.

What happens if you add a default @id @GeneratedValue(strategy="AUTO") and make your email just a column?

All works nice, if I add some ID in my class and make email field string. Hydration not works if you try hydrate array which contain entity IDs and entity was not found in database by this IDs (at least as I understand).

I think problem in DoctrineModule\Stdlib\Hydrator\DoctrineObject::tryConvertArrayToObject:

protected function tryConvertArrayToObject($data, $object)
{
    $identifierNames  = $this->metadata->getIdentifierFieldNames($object);
    $identifierValues = array();

    if (empty($identifierNames)) {
        return $object;
    }

    foreach ($identifierNames as $identifierName) {
        if (!isset($data[$identifierName]) || empty($data[$identifierName])) {
            return $object;
        }

        $identifierValues[$identifierName] = $data[$identifierName];
    }

    return $this->find(get_class($object), $identifierValues);
}

Maybe last line need to be replaced by:

if ( $existingEntity = $this->find(get_class($object), $identifierValues) ) {
    return $existingEntity;
 }
return $object;

I am not completely sure. But it will fix the error =)

from doctrinemodule.

Ocramius avatar Ocramius commented on June 15, 2024

I will close this one since the entire hydrator has been rewritten. Please verify against latest version (0.7.0 as of current date)

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.