Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
82e42123
Commit
82e42123
authored
Feb 23, 2010
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0][DDC-345] Fixed.
parent
4685a9ab
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
170 additions
and
4 deletions
+170
-4
Query.php
lib/Doctrine/ORM/Query.php
+2
-1
UnitOfWork.php
lib/Doctrine/ORM/UnitOfWork.php
+1
-1
BasicFunctionalTest.php
tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php
+10
-2
DDC345Test.php
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php
+157
-0
No files found.
lib/Doctrine/ORM/Query.php
View file @
82e42123
...
...
@@ -219,7 +219,8 @@ final class Query extends AbstractQuery
}
if
(
is_object
(
$value
))
{
$values
=
$this
->
_em
->
getClassMetadata
(
get_class
(
$value
))
->
getIdentifierValues
(
$value
);
//$values = $this->_em->getClassMetadata(get_class($value))->getIdentifierValues($value);
$values
=
$this
->
_em
->
getUnitOfWork
()
->
getEntityIdentifier
(
$value
);
//var_dump($this->_em->getUnitOfWork()->getEntityIdentifier($value));
$sqlPositions
=
$paramMappings
[
$key
];
$sqlParams
=
array_merge
(
$sqlParams
,
array_combine
((
array
)
$sqlPositions
,
$values
));
...
...
lib/Doctrine/ORM/UnitOfWork.php
View file @
82e42123
...
...
@@ -607,7 +607,6 @@ class UnitOfWork implements PropertyChangedListener
$idGen
=
$targetClass
->
idGenerator
;
if
(
!
$idGen
->
isPostInsertGenerator
())
{
$idValue
=
$idGen
->
generate
(
$this
->
_em
,
$entry
);
$this
->
_entityStates
[
$oid
]
=
self
::
STATE_MANAGED
;
if
(
!
$idGen
instanceof
\Doctrine\ORM\Id\Assigned
)
{
$this
->
_entityIdentifiers
[
$oid
]
=
array
(
$targetClass
->
identifier
[
0
]
=>
$idValue
);
$targetClass
->
getSingleIdReflectionProperty
()
->
setValue
(
$entry
,
$idValue
);
...
...
@@ -616,6 +615,7 @@ class UnitOfWork implements PropertyChangedListener
}
$this
->
addToIdentityMap
(
$entry
);
}
$this
->
_entityStates
[
$oid
]
=
self
::
STATE_MANAGED
;
// NEW entities are INSERTed within the current unit of work.
$this
->
_entityInsertions
[
$oid
]
=
$entry
;
...
...
tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php
View file @
82e42123
...
...
@@ -615,7 +615,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
/**
* @group ref
*/
/*
public function testQueryEntityByReference()
public
function
testQueryEntityByReference
()
{
$user
=
new
CmsUser
;
$user
->
name
=
'Guilherme'
;
...
...
@@ -633,13 +633,21 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this
->
_em
->
flush
();
$this
->
_em
->
clear
();
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
$userRef
=
$this
->
_em
->
getReference
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
$user
->
getId
());
$address2
=
$this
->
_em
->
createQuery
(
'select a from Doctrine\Tests\Models\CMS\CmsAddress a where a.user = :user'
)
->
setParameter
(
'user'
,
$userRef
)
->
getSingleResult
();
$this
->
assertTrue
(
$address2
->
getUser
()
instanceof
\Doctrine\ORM\Proxy\Proxy
);
$this
->
assertTrue
(
$userRef
===
$address2
->
getUser
());
$this
->
assertFalse
(
$userRef
->
__isInitialized__
);
$this
->
assertEquals
(
'Germany'
,
$address2
->
country
);
$this
->
assertEquals
(
'Berlin'
,
$address2
->
city
);
$this
->
assertEquals
(
'12345'
,
$address2
->
zip
);
}
*/
}
//DRAFT OF EXPECTED/DESIRED BEHAVIOR
/*public function testPersistentCollectionContainsDoesNeverInitialize()
...
...
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC345Test.php
0 → 100644
View file @
82e42123
<?php
namespace
Doctrine\Tests\ORM\Functional\Ticket
;
require_once
__DIR__
.
'/../../../TestInit.php'
;
class
DDC345Test
extends
\Doctrine\Tests\OrmFunctionalTestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
//$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger);
$this
->
_schemaTool
->
createSchema
(
array
(
$this
->
_em
->
getClassMetadata
(
__NAMESPACE__
.
'\DDC345User'
),
$this
->
_em
->
getClassMetadata
(
__NAMESPACE__
.
'\DDC345Group'
),
$this
->
_em
->
getClassMetadata
(
__NAMESPACE__
.
'\DDC345Membership'
),
));
}
public
function
testTwoIterateHydrations
()
{
// Create User
$user
=
new
DDC345User
;
$user
->
name
=
'Test User'
;
$this
->
_em
->
persist
(
$user
);
// $em->flush() does not change much here
// Create Group
$group
=
new
DDC345Group
;
$group
->
name
=
'Test Group'
;
$this
->
_em
->
persist
(
$group
);
// $em->flush() does not change much here
$membership
=
new
DDC345Membership
;
$membership
->
group
=
$group
;
$membership
->
user
=
$user
;
$membership
->
state
=
'active'
;
//$this->_em->persist($membership); // COMMENT OUT TO SEE BUG
/*
This should be not necessary, but without, its PrePersist is called twice,
$membership seems to be persisted twice, but all properties but the
ones set by LifecycleCallbacks are deleted.
*/
$user
->
Memberships
->
add
(
$membership
);
$group
->
Memberships
->
add
(
$membership
);
$this
->
_em
->
flush
();
$this
->
assertEquals
(
1
,
$membership
->
prePersistCallCount
);
$this
->
assertEquals
(
0
,
$membership
->
preUpdateCallCount
);
$this
->
assertTrue
(
$membership
->
updated
instanceof
\DateTime
);
}
}
/**
* @Entity
*/
class
DDC345User
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
public
$id
;
/** @Column(type="string") */
public
$name
;
/** @OneToMany(targetEntity="DDC345Membership", mappedBy="user", cascade={"persist"}) */
public
$Memberships
;
public
function
__construct
()
{
$this
->
Memberships
=
new
\Doctrine\Common\Collections\ArrayCollection
;
}
}
/**
* @Entity
*/
class
DDC345Group
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
public
$id
;
/** @Column(type="string") */
public
$name
;
/** @OneToMany(targetEntity="DDC345Membership", mappedBy="group", cascade={"persist"}) */
public
$Memberships
;
public
function
__construct
()
{
$this
->
Memberships
=
new
\Doctrine\Common\Collections\ArrayCollection
;
}
}
/**
* @Entity
* @HasLifecycleCallbacks
* @Table(name="ddc345_memberships", uniqueConstraints={
* @UniqueConstraint(name="ddc345_memship_fks", columns={"user_id","group_id"})
* })
*/
class
DDC345Membership
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
public
$id
;
/**
* @OneToOne(targetEntity="DDC345User")
* @JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
*/
public
$user
;
/**
* @OneToOne(targetEntity="DDC345Group")
* @JoinColumn(name="group_id", referencedColumnName="id", nullable=false)
*/
public
$group
;
/** @Column(type="string") */
public
$state
;
/** @Column(type="datetime") */
public
$updated
;
public
$prePersistCallCount
=
0
;
public
$preUpdateCallCount
=
0
;
/** @PrePersist */
public
function
doStuffOnPrePersist
()
{
//echo "***** PrePersist\n";
++
$this
->
prePersistCallCount
;
$this
->
updated
=
new
\DateTime
;
}
/** @PreUpdate */
public
function
doStuffOnPreUpdate
()
{
//echo "***** PreUpdate\n";
++
$this
->
preUpdateCallCount
;
$this
->
updated
=
new
\DateTime
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment