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
c54d5825
Commit
c54d5825
authored
Oct 22, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Added test coverage for native query with joined one-to-one association.
parent
a735cc08
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
1 deletion
+57
-1
ObjectHydrator.php
lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
+1
-0
CmsAddress.php
tests/Doctrine/Tests/Models/CMS/CmsAddress.php
+4
-0
NativeQueryTest.php
tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php
+52
-1
No files found.
lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
View file @
c54d5825
...
...
@@ -200,6 +200,7 @@ class ObjectHydrator extends AbstractHydrator
foreach
(
$assoc
->
targetToSourceKeyColumns
as
$srcColumn
)
{
$joinColumns
[
$srcColumn
]
=
$data
[
$assoc
->
joinColumnFieldNames
[
$srcColumn
]];
}
//TODO: If its in the identity map just get it from there if possible!
if
(
$assoc
->
isLazilyFetched
()
/*&& ! $assoc->isOptional*/
)
{
// Inject proxy
$proxy
=
$this
->
_proxyFactory
->
getAssociationProxy
(
$entity
,
$assoc
,
$joinColumns
);
...
...
tests/Doctrine/Tests/Models/CMS/CmsAddress.php
View file @
c54d5825
...
...
@@ -42,6 +42,10 @@ class CmsAddress
public
function
getId
()
{
return
$this
->
id
;
}
public
function
getUser
()
{
return
$this
->
user
;
}
public
function
getCountry
()
{
return
$this
->
country
;
...
...
tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php
View file @
c54d5825
...
...
@@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Functional;
use
Doctrine\ORM\Query\ResultSetMapping
;
use
Doctrine\Tests\Models\CMS\CmsUser
;
use
Doctrine\Tests\Models\CMS\CmsPhonenumber
;
use
Doctrine\Tests\Models\CMS\CmsAddress
;
require_once
__DIR__
.
'/../../TestInit.php'
;
...
...
@@ -50,7 +51,7 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this
->
assertEquals
(
'Roman'
,
$users
[
0
]
->
name
);
}
public
function
testJoinedNativeQuery
()
public
function
testJoined
OneToMany
NativeQuery
()
{
$user
=
new
CmsUser
;
$user
->
name
=
'Roman'
;
...
...
@@ -83,11 +84,61 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this
->
assertTrue
(
$users
[
0
]
instanceof
CmsUser
);
$this
->
assertEquals
(
'Roman'
,
$users
[
0
]
->
name
);
$this
->
assertTrue
(
$users
[
0
]
->
getPhonenumbers
()
instanceof
\Doctrine\ORM\PersistentCollection
);
$this
->
assertTrue
(
$users
[
0
]
->
getPhonenumbers
()
->
isInitialized
());
$this
->
assertEquals
(
1
,
count
(
$users
[
0
]
->
getPhonenumbers
()));
$phones
=
$users
[
0
]
->
getPhonenumbers
();
$this
->
assertEquals
(
424242
,
$phones
[
0
]
->
phonenumber
);
$this
->
assertTrue
(
$phones
[
0
]
->
getUser
()
===
$users
[
0
]);
}
public
function
testJoinedOneToOneNativeQuery
()
{
$user
=
new
CmsUser
;
$user
->
name
=
'Roman'
;
$user
->
username
=
'romanb'
;
$user
->
status
=
'dev'
;
$addr
=
new
CmsAddress
;
$addr
->
country
=
'germany'
;
$addr
->
zip
=
10827
;
$addr
->
city
=
'Berlin'
;
$user
->
setAddress
(
$addr
);
$this
->
_em
->
persist
(
$user
);
$this
->
_em
->
flush
();
$this
->
_em
->
clear
();
$rsm
=
new
ResultSetMapping
;
$rsm
->
addEntityResult
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'u'
);
$rsm
->
addFieldResult
(
'u'
,
'id'
,
'id'
);
$rsm
->
addFieldResult
(
'u'
,
'name'
,
'name'
);
$rsm
->
addFieldResult
(
'u'
,
'status'
,
'status'
);
$rsm
->
addJoinedEntityResult
(
'Doctrine\Tests\Models\CMS\CmsAddress'
,
'a'
,
'u'
,
'address'
);
$rsm
->
addFieldResult
(
'a'
,
'a_id'
,
'id'
);
$rsm
->
addFieldResult
(
'a'
,
'country'
,
'country'
);
$rsm
->
addFieldResult
(
'a'
,
'zip'
,
'zip'
);
$rsm
->
addFieldResult
(
'a'
,
'city'
,
'city'
);
$query
=
$this
->
_em
->
createNativeQuery
(
'SELECT u.id, u.name, u.status, a.id AS a_id, a.country, a.zip, a.city FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?'
,
$rsm
);
$query
->
setParameter
(
1
,
'romanb'
);
$users
=
$query
->
getResult
();
$this
->
assertEquals
(
1
,
count
(
$users
));
$this
->
assertTrue
(
$users
[
0
]
instanceof
CmsUser
);
$this
->
assertEquals
(
'Roman'
,
$users
[
0
]
->
name
);
$this
->
assertTrue
(
$users
[
0
]
->
getPhonenumbers
()
instanceof
\Doctrine\ORM\PersistentCollection
);
$this
->
assertFalse
(
$users
[
0
]
->
getPhonenumbers
()
->
isInitialized
());
$this
->
assertTrue
(
$users
[
0
]
->
getAddress
()
instanceof
CmsAddress
);
$this
->
assertTrue
(
$users
[
0
]
->
getAddress
()
->
getUser
()
==
$users
[
0
]);
$this
->
assertEquals
(
'germany'
,
$users
[
0
]
->
getAddress
()
->
getCountry
());
$this
->
assertEquals
(
10827
,
$users
[
0
]
->
getAddress
()
->
getZipCode
());
$this
->
assertEquals
(
'Berlin'
,
$users
[
0
]
->
getAddress
()
->
getCity
());
}
}
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