A new entity was found through the relationship doctrine error

Doctrine error: New Entity was found through relationship

This is typical problem of doctrine with joined relations.

How to use MySQL keyword as column in doctrine

And, to be specific, this would happen when trying to save an entity with relationship and the one being joined is fetched from memcached/redis or from other entity manager or you just populated it and not getting through Entity Manager

Solution to the doctrine error

Use the merge on EntityManager before you persist the object

Say you have an entity for pen and entity for color as well.. You want to save a new pen but you assigned a color from memcached object


$color = $this->memcacheGiveMeColor('blue');
$color = $em->merge($color)
$pen->setColor($color);
$em->persist($pen);
$em->flush();

Make sure you are using the object that is returned from merge!

If you are not reading from the memcached or other factory, and you are reading directly from Entity Manager then you wont have this error.

Start using mongoDB with nodeJS even though you haven’t been using it before

What is http raw data? what is php://input and where to use which?

Doctrine orm:convert-mappings errors on primary key

Doctrine error orm:convert-mappings

Doctrine orm error like above? I have been there.

The solution I am providing is not that great solution but it can keep you going for a while.

A tool for generating entities for doctrine orm from the database table without primary key might complain as:

has no primary key. Doctrine does not support reverse engineering from tables that don’t have a primary key.

From the code base search for DatabaseDriver.php file:

Go to DatabaseDriver.php

Search for reverseEngineerMappingFromDatabase method in the given file.

uncomment the the following part as follows

           //if ( ! $table->hasPrimaryKey()) {
              //  throw new MappingException(
                //    "Table " . $table->getName() . " has no primary key. Doctrine does not ".
                  //  "support reverse engineering from tables that don't have a primary key."
                //);
            //}

            //$pkColumns = $table->getPrimaryKey()->getColumns();

Add the following line

$pkColumns = array();

Then search for method getTablePrimaryKeys and comment everything inside it and return empty array.

The above method will remove the has no primary key. Doctrine does not support reverse engineering from tables that don’t have a primary key. error when using entity generation tool.

Single id is not allowed on composite primary key in entity Doctrine error

You might get the above error on PHP Doctrine

if you got the above error, then it means you have two or more ids as primary in your object representing the table.

Example:

class Member
   /** @id 
    * @Column(type="integer") 
    * @GeneratedValue(strategy="AUTO")
    */
   private $id;
   /** @id @Column(type="string") */
   private $key;
...

The above declaration would create the above error and taking out the generatedValue part can resolve the issue.

See the solution to common error of new entity was found though relation while using doctrine