[DDC-3746] lack of flexibility in persisters Created: 25/May/15  Updated: 25/May/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Improvement Priority: Major
Reporter: KonstantinKuklin Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

I tried to implement driver for HandlerSocket protocol, which is mysql nosql plugin.

BasicEntityPersister is a problem - it fully depends(and others and more) on SQL.
I can`t say to Doctrine, how the data must be fetched from my own Driver.
I think it is a logical mistake, such logic(creating query to DB) must be inside a db driver bridge.
I found two solution:
1) Get persisters configurable from entity manager config
2) Try to find persisters inside the DBAL driver

What do u think about it?

Thanks, Konstantin.






[DDC-3745] OneToOne identity through foreign entity exception on flush Created: 22/May/15  Updated: 22/May/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Minor
Reporter: Dawid Nowak Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

Also asked at SO: https://stackoverflow.com/questions/30402203
I'm adding it here as well as an issue here, because I believe it just might be Doctrine's bug.


I have `User` and `UserProfile` OneToOne–related Doctrine ORM entities. They should always exist as a pair, there should be no `User` without `UserProfile`.

User should get its id from autoincrement, while UserProfile should have User's id. So they both should have the same id and there is no other column to set up the relationship ([Doctrine docs: Identity through foreign Entities](https://doctrine-orm.readthedocs.org/en/latest/tutorials/composite-primary-keys.html#identity-through-foreign-entities)).

User's id is both a primary key (PK) and foreign key (FK) at the same time.

I managed to set it up, but it requires that User is saved first and only later UserProfile is created and saved in a separate step.

What I want is that UserProfile is always created with User, in the constructor, but if I do that, I get this exception:

`Doctrine\ORM\ORMInvalidArgumentException: The given entity of type 'AppBundle\Entity\UserProfile' (AppBundle\Entity\UserProfile@0000000052e1b1eb00000000409c6f2c) has no identity/no id values set. It cannot be added to the identity map.`

Please see code below – it works, but not the way I want. The php comments show what I want to achieve.

Test.php
    /**
     * It works, both saving and loading.
     * BUT, it requires that I create and save UserProfile 
     * in a separate step than saving User step.
     */
    
    // create and save User
    $user = new User();
    $objectManager->persist($user);
    $objectManager->flush();
    
    // create and save UserProfile (this should be unnecessary)
    $user->createProfile()
    $objectManager->flush();
User.php
    use Doctrine\ORM\Mapping as ORM;
    
    /**
     * @ORM\Entity(repositoryClass="AppBundle\Entity\UserRepository")
     * @ORM\Table(name="users")
     */
    class User
    {
    	/**
    	 * @var int
    	 *
    	 * @ORM\Column(name="uid", type="integer")
    	 * @ORM\Id
    	 * @ORM\GeneratedValue(strategy="AUTO")
    	 */
    	private $id;
    	
    	/**
    	 * It's NULL at first, I create it later (after saving User).
    	 * 
    	 * @var UserProfile|null
    	 *
    	 * @ORM\OneToOne(targetEntity="UserProfile", mappedBy="user", cascade="persist")
    	 */
    	private $profile = null;
    	
    	public function __construct()
    	{
    		// I want to create UserProfile inside User's constructor,
    		// so that it is always present (never NULL):
    		//$this->profile = new UserProfile($this);
    		
    		// but this would give me error:
    		//
    		// Doctrine\ORM\ORMInvalidArgumentException: 
    		// The given entity of type 'AppBundle\Entity\UserProfile' 
    		// (AppBundle\Entity\UserProfile@0000000058af220a0000000079dc875a)
    		// has no identity/no id values set. It cannot be added to the identity map.
    	}
    
    	public function createProfile()
    	{
    		$this->profile = new UserProfile($this);
    	}	
    }
UserProfile.php
    
    use Doctrine\ORM\Mapping as ORM;
    
    /**
     * @ORM\Entity
     * @ORM\Table(name="profiles")
     */
    class UserProfile
    {
    	/**
    	 * – UserProfile's "uid" column points to User's "uid" column
    	 * – it is PK (primary key)
    	 * - it is FK (foreign key) as well
    	 * – "owning side"
    	 *
    	 * @var User
    	 *
    	 * @ORM\Id
    	 * @ORM\OneToOne(targetEntity="User", inversedBy="profile")
    	 * @ORM\JoinColumn(name="uid", referencedColumnName="uid", nullable=false)
    	*/
    	private $user;
        
    	public function __construct(User $user)
    	{
    		$this->user = $user;
    	}    
    }





[DDC-3744] [GH-1412] Added RANDOM() function to DQL Created: 22/May/15  Updated: 22/May/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: New Feature Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

This issue is created automatically through a Github pull request on behalf of cverges-ch:

Url: https://github.com/doctrine/doctrine2/pull/1412

Message:

Corresponds with generic platform support for a random number generator mechanism typically implemented by most DBMS.

See pull request at https://github.com/doctrine/dbal/pull/865

Use of RAND(), random(), DBMS_RANDOM.VALUE, or whatever the platform provides as a random number generator can be essential to some business logic. This adds generic platform support for this mechanism and introduces a new DQL keyword "RANDOM()".

DBAL: https://github.com/doctrine/dbal/pull/865
DQL: https://github.com/doctrine/doctrine2/pull/1412






[DDC-3743] There is a BC break in the ORM 2.5 in the DQL parser Created: 22/May/15  Updated: 22/May/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: DQL
Affects Version/s: 2.5
Fix Version/s: None
Security Level: All

Type: Bug Priority: Critical
Reporter: Christophe Coevoet Assignee: Guilherme Blanco
Resolution: Unresolved Votes: 0
Labels: dql


 Description   

The following DQL query is working fine on 2.4 but breaks on 2.5:

SELECT COUNT(l) FROM Incenteev\WebBundle\Entity\Discussion\Liker l INNER JOIN l.message m INNER JOIN m.thread t WHERE t.space IN (:space_ids) AND l.date >= :from

This is the exception triggered in 2.5:

[Semantical Error] line 0, col 13 near 'l) FROM Incenteev\WebBundle\Entity\Discussion\Liker': Error: Invalid PathExpression. Must be a StateFieldPathExpression. 

The exception happens in Parser->processDeferredPathExpressions.

The Liker class has a compound identifier based on 2 relations.

I suspect it is related to https://github.com/doctrine/doctrine2/pull/1122



 Comments   
Comment by Christophe Coevoet [ 22/May/15 ]

I'm not sure it is a BC break though. Looking at the SQL generated in 2.4, it was not counting the right thing (is was counting only the message ids, not the combination message id/user id being the primary key.





[DDC-3742] Use UTCDatetimeType with lifecycle callbacks Created: 22/May/15  Updated: 22/May/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.4.7
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: pablo Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: dbal, orm
Environment:

Fedora 20 x64 with Phalcon 2.0 and doctrine downloaded via composer:
"doctrine/orm": "2.*",
"doctrine/mongodb-odm": "dev-master",



 Description   

I'm trying to save my entities (yaml), which have lifecyclecallbacks with a createdAt and updatedAt UTCDatetimeType fields. If I save them with prePersist or preUpdate, the insert of new rows into the mysql database fails because of blank date fields, but they are already populated in my entity.

If I replace the UTCDateTimeType by datetime, it works.



 Comments   
Comment by pablo [ 22/May/15 ]

I'm using UTCDateTimeType from: http://doctrine-orm.readthedocs.org/en/latest/cookbook/working-with-datetime.html

It makes a $value->format($format, $timezone)

I was passing a \Datetime object, so format only has one parameter, not 2...Then, Or I'm passing an unexpected $value or the format method is not properly coded there.

So, I've modified convertToDatabaseValue to the following:

        if ($value === null) {
            return null;
        }

        if (is_null(self::$utc)) {
            self::$utc = new \DateTimeZone('UTC');
        }

        if (!($value instanceof \DateTime)) {
            $value = \DateTime::createFromFormat(
                $platform->getDateTimeFormatString(),
                $value,
                self::$utc
            );
        }

        $value->setTimeZone(self::$utc);

        $val = $value->format($platform->getDateTimeFormatString());

        return $val;
Comment by Marco Pivetta [ 22/May/15 ]

pablo what exactly is the action to be taken here? It's unclear to me.

Comment by pablo [ 22/May/15 ]

I replaced the metod convertToDatabaseValue from http://doctrine-orm.readthedocs.org/en/latest/cookbook/working-with-datetime.html with mine.

For example:

<code>
date_default_timezone_set('Europe/Madrid');
$expireAt = new \DateTime();
$entity = newEntity();
$entity->setExpireAt($expireAt);

$this->em->persist($entity);
$this->em->flush();
</code>

My expireAt field is UTCDateTimeType, so it will be converted from my Europe/Madrid timezone to UTC. But using the code from URL it doesn't works because ->format() method has 2 parameters instead of one.





[DDC-3741] [GH-1411] Allow null to be passed to setHydrationCacheProfile Created: 20/May/15  Updated: 20/May/15

Status: Open
Project: Doctrine 2 - ORM
Component/s: None
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Doctrine Bot Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 0
Labels: None


 Description   

This issue is created automatically through a Github pull request on behalf of icambridge:

Url: https://github.com/doctrine/doctrine2/pull/1411

Message:

Currently null can be passed and is set as default, however if you do this you get an exception. This allows null to be passed and set.

There is an if statement later on to see if $this->_hydrationCacheProfile is null so it seems logical you can set it to be null.






Generated at Mon May 25 23:34:51 UTC 2015 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.