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
7c81b0b0
Commit
7c81b0b0
authored
Feb 26, 2010
by
jwage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Adding support for entity aliases in the query language
parent
50e9d8c5
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
3 deletions
+58
-3
AnnotationReader.php
lib/Doctrine/Common/Annotations/AnnotationReader.php
+1
-1
Configuration.php
lib/Doctrine/ORM/Configuration.php
+34
-1
ClassMetadataFactory.php
lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
+4
-0
Parser.php
lib/Doctrine/ORM/Query/Parser.php
+4
-0
QueryTest.php
tests/Doctrine/Tests/ORM/Functional/QueryTest.php
+15
-1
No files found.
lib/Doctrine/Common/Annotations/AnnotationReader.php
View file @
7c81b0b0
...
@@ -70,7 +70,7 @@ class AnnotationReader
...
@@ -70,7 +70,7 @@ class AnnotationReader
public
function
__construct
(
Cache
$cache
=
null
)
public
function
__construct
(
Cache
$cache
=
null
)
{
{
$this
->
_parser
=
new
Parser
;
$this
->
_parser
=
new
Parser
;
$this
->
_cache
=
$cache
?:
new
Doctrine\Common\Cache\ArrayCache
;
$this
->
_cache
=
$cache
?:
new
\
Doctrine\Common\Cache\ArrayCache
;
}
}
/**
/**
...
...
lib/Doctrine/ORM/Configuration.php
View file @
7c81b0b0
...
@@ -51,7 +51,8 @@ class Configuration extends \Doctrine\DBAL\Configuration
...
@@ -51,7 +51,8 @@ class Configuration extends \Doctrine\DBAL\Configuration
'namedQueries'
=>
array
(),
'namedQueries'
=>
array
(),
'namedNativeQueries'
=>
array
(),
'namedNativeQueries'
=>
array
(),
'autoGenerateProxyClasses'
=>
true
,
'autoGenerateProxyClasses'
=>
true
,
'proxyNamespace'
=>
null
'proxyNamespace'
=>
null
,
'entityAliasMap'
=>
array
()
));
));
}
}
...
@@ -119,6 +120,38 @@ class Configuration extends \Doctrine\DBAL\Configuration
...
@@ -119,6 +120,38 @@ class Configuration extends \Doctrine\DBAL\Configuration
$this
->
_attributes
[
'metadataDriverImpl'
]
=
$driverImpl
;
$this
->
_attributes
[
'metadataDriverImpl'
]
=
$driverImpl
;
}
}
/**
* Add an alias for an entity.
*
* @param string $className
* @param string $alias
*/
public
function
addEntityAlias
(
$className
,
$alias
)
{
$this
->
_attributes
[
'entityAliasMap'
][
$alias
]
=
$className
;
}
/**
* get the array of entity aliases
*
* @return array $aliasMap
*/
public
function
getEntityAliasMap
()
{
return
$this
->
_attributes
[
'entityAliasMap'
];
}
/**
* Set the entity alias map
*
* @param array $entityAliasMap
* @return void
*/
public
function
setEntityAliasMap
(
array
$entityAliasMap
)
{
$this
->
_attributes
[
'entityAliasMap'
]
=
$entityAliasMap
;
}
/**
/**
* Gets the cache driver implementation that is used for the mapping metadata.
* Gets the cache driver implementation that is used for the mapping metadata.
*
*
...
...
lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
View file @
7c81b0b0
...
@@ -128,6 +128,10 @@ class ClassMetadataFactory
...
@@ -128,6 +128,10 @@ class ClassMetadataFactory
public
function
getMetadataFor
(
$className
)
public
function
getMetadataFor
(
$className
)
{
{
if
(
!
isset
(
$this
->
_loadedMetadata
[
$className
]))
{
if
(
!
isset
(
$this
->
_loadedMetadata
[
$className
]))
{
$aliasMap
=
$this
->
_em
->
getConfiguration
()
->
getEntityAliasMap
();
if
(
isset
(
$aliasMap
[
$className
]))
{
$className
=
$aliasMap
[
$className
];
}
$cacheKey
=
"
$className
\$
CLASSMETADATA"
;
$cacheKey
=
"
$className
\$
CLASSMETADATA"
;
if
(
$this
->
_cacheDriver
)
{
if
(
$this
->
_cacheDriver
)
{
if
((
$cached
=
$this
->
_cacheDriver
->
fetch
(
$cacheKey
))
!==
false
)
{
if
((
$cached
=
$this
->
_cacheDriver
->
fetch
(
$cacheKey
))
!==
false
)
{
...
...
lib/Doctrine/ORM/Query/Parser.php
View file @
7c81b0b0
...
@@ -867,6 +867,10 @@ class Parser
...
@@ -867,6 +867,10 @@ class Parser
$this
->
match
(
Lexer
::
T_IDENTIFIER
);
$this
->
match
(
Lexer
::
T_IDENTIFIER
);
$schemaName
=
$this
->
_lexer
->
token
[
'value'
];
$schemaName
=
$this
->
_lexer
->
token
[
'value'
];
$aliasMap
=
$this
->
_em
->
getConfiguration
()
->
getEntityAliasMap
();
if
(
isset
(
$aliasMap
[
$schemaName
]))
{
$schemaName
=
$aliasMap
[
$schemaName
];
}
$exists
=
class_exists
(
$schemaName
,
true
);
$exists
=
class_exists
(
$schemaName
,
true
);
if
(
!
$exists
)
{
if
(
!
$exists
)
{
...
...
tests/Doctrine/Tests/ORM/Functional/QueryTest.php
View file @
7c81b0b0
...
@@ -226,5 +226,19 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
...
@@ -226,5 +226,19 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this
->
_em
->
createQuery
(
"select a from Doctrine\Tests\Models\CMS\CmsArticle a"
)
$this
->
_em
->
createQuery
(
"select a from Doctrine\Tests\Models\CMS\CmsArticle a"
)
->
getSingleResult
();
->
getSingleResult
();
}
}
}
public
function
testSupportsQueriesWithEntityAliases
()
{
$this
->
_em
->
getConfiguration
()
->
addEntityAlias
(
'Doctrine\Tests\Models\CMS\CmsUser'
,
'TestAlias'
);
try
{
$query
=
$this
->
_em
->
createQuery
(
'UPDATE TestAlias u SET u.name = ?1'
);
$this
->
assertEquals
(
'UPDATE cms_users SET name = ?'
,
$query
->
getSql
());
$query
->
free
();
}
catch
(
\Exception
$e
)
{
$this
->
fail
(
$e
->
getMessage
());
}
$this
->
_em
->
getConfiguration
()
->
setEntityAliasMap
(
array
());
}
}
\ No newline at end of file
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