yml driver
This commit is contained in:
parent
531eb68d56
commit
b49180875c
@ -224,6 +224,7 @@ class AnnotationDriver implements Driver
|
||||
|
||||
foreach ($sqlResultSetMappingsAnnot->value as $resultSetMapping) {
|
||||
$entities = array();
|
||||
$columns = array();
|
||||
foreach ($resultSetMapping->entities as $entityResultAnnot) {
|
||||
$entityResult = array(
|
||||
'fields' => array(),
|
||||
@ -241,7 +242,6 @@ class AnnotationDriver implements Driver
|
||||
$entities[] = $entityResult;
|
||||
}
|
||||
|
||||
$columns = array();
|
||||
foreach ($resultSetMapping->columns as $columnResultAnnot) {
|
||||
$columns[] = array(
|
||||
'name' => $columnResultAnnot->name,
|
||||
|
@ -83,6 +83,68 @@ class YamlDriver extends AbstractFileDriver
|
||||
}
|
||||
}
|
||||
|
||||
// Evaluate named native queries
|
||||
if (isset($element['namedNativeQueries'])) {
|
||||
foreach ($element['namedNativeQueries'] as $name => $mappingElement) {
|
||||
if (!isset($mappingElement['name'])) {
|
||||
$mappingElement['name'] = $name;
|
||||
}
|
||||
$metadata->addNamedNativeQuery(array(
|
||||
'name' => $mappingElement['name'],
|
||||
'query' => isset($mappingElement['query']) ? $mappingElement['query'] : null,
|
||||
'resultClass' => isset($mappingElement['resultClass']) ? $mappingElement['resultClass'] : null,
|
||||
'resultSetMapping' => isset($mappingElement['resultSetMapping']) ? $mappingElement['resultSetMapping'] : null,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Evaluate sql result set mappings
|
||||
if (isset($element['sqlResultSetMappings'])) {
|
||||
foreach ($element['sqlResultSetMappings'] as $name => $resultSetMapping) {
|
||||
if (!isset($resultSetMapping['name'])) {
|
||||
$resultSetMapping['name'] = $name;
|
||||
}
|
||||
|
||||
$entities = array();
|
||||
$columns = array();
|
||||
if (isset($resultSetMapping['entityResult'])) {
|
||||
foreach ($resultSetMapping['entityResult'] as $entityResultElement) {
|
||||
$entityResult = array(
|
||||
'fields' => array(),
|
||||
'entityClass' => isset($entityResultElement['entityClass']) ? $entityResultElement['entityClass'] : null,
|
||||
'discriminatorColumn' => isset($entityResultElement['discriminatorColumn']) ? $entityResultElement['discriminatorColumn'] : null,
|
||||
);
|
||||
|
||||
if (isset($entityResultElement['fieldResult'])) {
|
||||
foreach ($entityResultElement['fieldResult'] as $fieldResultElement) {
|
||||
$entityResult['fields'][] = array(
|
||||
'name' => isset($fieldResultElement['name']) ? $fieldResultElement['name'] : null,
|
||||
'column' => isset($fieldResultElement['column']) ? $fieldResultElement['column'] : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$entities[] = $entityResult;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (isset($resultSetMapping['columnResult'])) {
|
||||
foreach ($resultSetMapping['columnResult'] as $columnResultAnnot) {
|
||||
$columns[] = array(
|
||||
'name' => isset($columnResultAnnot['name']) ? $columnResultAnnot['name'] : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$metadata->addSqlResultSetMapping(array(
|
||||
'name' => $resultSetMapping['name'],
|
||||
'entities' => $entities,
|
||||
'columns' => $columns
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/* not implemented specially anyway. use table = schema.table
|
||||
if (isset($element['schema'])) {
|
||||
$metadata->table['schema'] = $element['schema'];
|
||||
@ -484,10 +546,14 @@ class YamlDriver extends AbstractFileDriver
|
||||
*/
|
||||
private function _getJoinColumnMapping($joinColumnElement)
|
||||
{
|
||||
$joinColumn = array(
|
||||
'name' => $joinColumnElement['name'],
|
||||
'referencedColumnName' => $joinColumnElement['referencedColumnName']
|
||||
);
|
||||
$joinColumn = array();
|
||||
if (isset($joinColumnElement['referencedColumnName'])) {
|
||||
$joinColumn['referencedColumnName'] = (string) $joinColumnElement['referencedColumnName'];
|
||||
}
|
||||
|
||||
if (isset($joinColumnElement['name'])) {
|
||||
$joinColumn['name'] = (string) $joinColumnElement['name'];
|
||||
}
|
||||
|
||||
if (isset($joinColumnElement['fieldName'])) {
|
||||
$joinColumn['fieldName'] = (string) $joinColumnElement['fieldName'];
|
||||
|
@ -495,7 +495,9 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
||||
*/
|
||||
public function testNamedNativeQuery()
|
||||
{
|
||||
if (!$this instanceof AnnotationDriverTest && !$this instanceof XmlMappingDriverTest) {
|
||||
if (!$this instanceof AnnotationDriverTest &&
|
||||
!$this instanceof XmlMappingDriverTest &&
|
||||
!$this instanceof YamlMappingDriverTest) {
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
@ -551,7 +553,9 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
||||
*/
|
||||
public function testSqlResultSetMapping()
|
||||
{
|
||||
if (!$this instanceof AnnotationDriverTest && !$this instanceof XmlMappingDriverTest) {
|
||||
if (!$this instanceof AnnotationDriverTest &&
|
||||
!$this instanceof XmlMappingDriverTest &&
|
||||
!$this instanceof YamlMappingDriverTest) {
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
|
||||
|
@ -46,17 +46,9 @@
|
||||
<field name="country" column="country" type="string" length="50"/>
|
||||
<field name="city" column="city" type="string" length="50"/>
|
||||
<field name="zip" column="zip" type="string" length="50"/>
|
||||
|
||||
|
||||
<one-to-one field="address" target-entity="CmsAddress" inversed-by="user" orphan-removal="true">
|
||||
<cascade>
|
||||
<cascade-persist/>
|
||||
</cascade>
|
||||
<join-column name="address_id" referenced-column-name="id" />
|
||||
</one-to-one>
|
||||
|
||||
<one-to-one field="email" target-entity="CmsUser" inversed-by="address">
|
||||
<join-column referenced-column-name="id" nullable="true" />
|
||||
<one-to-one field="user" target-entity="CmsUser" inversed-by="address">
|
||||
<join-column referenced-column-name="id" />
|
||||
</one-to-one>
|
||||
|
||||
</entity>
|
||||
|
@ -0,0 +1,62 @@
|
||||
Doctrine\Tests\Models\CMS\CmsAddress:
|
||||
type: entity
|
||||
table: cms_address
|
||||
namedNativeQueries:
|
||||
find-all:
|
||||
resultSetMapping: mapping-find-all
|
||||
query: SELECT id, country, city FROM cms_addresses
|
||||
find-by-id:
|
||||
name: find-by-id
|
||||
resultClass: CmsAddress
|
||||
query: SELECT * FROM cms_addresses WHERE id = ?
|
||||
count:
|
||||
name: count
|
||||
resultSetMapping: mapping-count
|
||||
query: SELECT COUNT(*) AS count FROM cms_addresses
|
||||
|
||||
sqlResultSetMappings:
|
||||
mapping-find-all:
|
||||
entityResult:
|
||||
address:
|
||||
entityClass: CmsAddress
|
||||
fieldResult:
|
||||
0:
|
||||
name: id
|
||||
column: id
|
||||
1:
|
||||
name: city
|
||||
column: city
|
||||
2:
|
||||
name: country
|
||||
column: country
|
||||
mapping-without-fields:
|
||||
name: mapping-without-fields
|
||||
entityResult:
|
||||
address:
|
||||
entityClass: CmsAddress
|
||||
mapping-count:
|
||||
name: mapping-count
|
||||
columnResult:
|
||||
count:
|
||||
name: count
|
||||
id:
|
||||
id:
|
||||
type: integer
|
||||
generator:
|
||||
strategy: AUTO
|
||||
fields:
|
||||
country:
|
||||
type: string
|
||||
length: 50
|
||||
city:
|
||||
type: string
|
||||
length: 50
|
||||
zip:
|
||||
type: string
|
||||
length: 50
|
||||
oneToOne:
|
||||
address:
|
||||
targetEntity: CmsUser
|
||||
inversedBy: address
|
||||
joinColumn:
|
||||
referencedColumnName: id
|
@ -0,0 +1,124 @@
|
||||
Doctrine\Tests\Models\CMS\CmsUser:
|
||||
type: entity
|
||||
table: cms_users
|
||||
namedQueries:
|
||||
all: SELECT u FROM __CLASS__ u
|
||||
namedNativeQueries:
|
||||
fetchIdAndUsernameWithResultClass:
|
||||
resultClass: CmsUser
|
||||
query: SELECT id, username FROM cms_users WHERE username = ?
|
||||
fetchAllColumns:
|
||||
name: fetchAllColumns
|
||||
resultClass: CmsUser
|
||||
query: SELECT * FROM cms_users WHERE username = ?
|
||||
fetchJoinedAddress:
|
||||
name: fetchJoinedAddress
|
||||
resultSetMapping: mappingJoinedAddress
|
||||
query: 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 = ?
|
||||
fetchJoinedPhonenumber:
|
||||
name: fetchJoinedPhonenumber
|
||||
resultSetMapping: mappingJoinedPhonenumber
|
||||
query: SELECT id, name, status, phonenumber AS number FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username = ?
|
||||
fetchUserPhonenumberCount:
|
||||
name: fetchUserPhonenumberCount
|
||||
resultSetMapping: mappingUserPhonenumberCount
|
||||
query: SELECT id, name, status, COUNT(phonenumber) AS numphones FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username IN (?) GROUP BY id, name, status, username ORDER BY username
|
||||
|
||||
sqlResultSetMappings:
|
||||
mappingJoinedAddress:
|
||||
entityResult:
|
||||
0:
|
||||
entityClass: __CLASS__
|
||||
fieldResult:
|
||||
0:
|
||||
name: id
|
||||
1:
|
||||
name: name
|
||||
2:
|
||||
name: status
|
||||
3:
|
||||
name: address.zip
|
||||
4:
|
||||
name: address.city
|
||||
5:
|
||||
name: address.country
|
||||
6:
|
||||
name: address.id
|
||||
column: a_id
|
||||
mappingJoinedPhonenumber:
|
||||
name: mappingJoinedPhonenumber
|
||||
entityResult:
|
||||
user:
|
||||
entityClass: CmsUser
|
||||
fieldResult:
|
||||
0:
|
||||
name: id
|
||||
1:
|
||||
name: name
|
||||
2:
|
||||
name: status
|
||||
3:
|
||||
name: phonenumbers.phonenumber
|
||||
column: number
|
||||
mappingUserPhonenumberCount:
|
||||
name: mappingUserPhonenumberCount
|
||||
columnResult:
|
||||
0:
|
||||
name: numphones
|
||||
entityResult:
|
||||
user_0:
|
||||
entityClass: CmsUser
|
||||
fieldResult:
|
||||
0:
|
||||
name: id
|
||||
1:
|
||||
name: name
|
||||
2:
|
||||
name: status
|
||||
id:
|
||||
id:
|
||||
type: integer
|
||||
generator:
|
||||
strategy: AUTO
|
||||
fields:
|
||||
name:
|
||||
type: string
|
||||
length: 255
|
||||
username:
|
||||
type: string
|
||||
length: 255
|
||||
unique: true
|
||||
status:
|
||||
type: string
|
||||
length: 50
|
||||
unique: true
|
||||
oneToOne:
|
||||
address:
|
||||
targetEntity: CmsAddress
|
||||
orphanRemoval: true
|
||||
inversedBy: user
|
||||
joinColumn:
|
||||
name: address_id
|
||||
referencedColumnName: id
|
||||
cascade: [ persist ]
|
||||
oneToOne:
|
||||
email:
|
||||
targetEntity: CmsEmail
|
||||
orphanRemoval: true
|
||||
inversedBy: user
|
||||
joinColumn:
|
||||
nullable: true
|
||||
referencedColumnName: id
|
||||
cascade: [ persist ]
|
||||
manyToMany:
|
||||
groups:
|
||||
targetEntity: CmsGroup
|
||||
joinTable:
|
||||
name: cms_users_groups
|
||||
joinColumns:
|
||||
user_id:
|
||||
referencedColumnName: id
|
||||
inverseJoinColumns:
|
||||
group_id:
|
||||
referencedColumnName: id
|
||||
cascade: [ persist , detach, merge]
|
@ -0,0 +1,75 @@
|
||||
Doctrine\Tests\Models\Company\CompanyPerson:
|
||||
type: entity
|
||||
table: company_persons
|
||||
inheritanceType: JOINED
|
||||
discriminatorMap:
|
||||
person: CompanyPerson
|
||||
manager: CompanyManager
|
||||
employee: CompanyEmployee
|
||||
namedNativeQueries:
|
||||
fetchAllWithResultClass:
|
||||
resultClass: __CLASS__
|
||||
query: SELECT id, name, discr FROM company_persons ORDER BY name
|
||||
fetchAllWithSqlResultSetMapping:
|
||||
name: fetchAllWithSqlResultSetMapping
|
||||
resultSetMapping: mappingFetchAll
|
||||
query: SELECT id, name, discr AS discriminator FROM company_persons ORDER BY name
|
||||
|
||||
sqlResultSetMappings:
|
||||
mappingFetchAll:
|
||||
entityResult:
|
||||
0:
|
||||
entityClass: __CLASS__
|
||||
discriminatorColumn: discriminator
|
||||
fieldResult:
|
||||
0:
|
||||
name: id
|
||||
1:
|
||||
name: name
|
||||
id:
|
||||
id:
|
||||
type: integer
|
||||
generator:
|
||||
strategy: AUTO
|
||||
fields:
|
||||
name:
|
||||
type: string
|
||||
length: 255
|
||||
username:
|
||||
type: string
|
||||
length: 255
|
||||
unique: true
|
||||
status:
|
||||
type: string
|
||||
length: 50
|
||||
unique: true
|
||||
oneToOne:
|
||||
address:
|
||||
targetEntity: CmsAddress
|
||||
orphanRemoval: true
|
||||
inversedBy: user
|
||||
joinColumn:
|
||||
name: address_id
|
||||
referencedColumnName: id
|
||||
cascade: [ persist ]
|
||||
oneToOne:
|
||||
email:
|
||||
targetEntity: CmsEmail
|
||||
orphanRemoval: true
|
||||
inversedBy: user
|
||||
joinColumn:
|
||||
nullable: true
|
||||
referencedColumnName: id
|
||||
cascade: [ persist ]
|
||||
manyToMany:
|
||||
groups:
|
||||
targetEntity: CmsGroup
|
||||
joinTable:
|
||||
name: cms_users_groups
|
||||
joinColumns:
|
||||
user_id:
|
||||
referencedColumnName: id
|
||||
inverseJoinColumns:
|
||||
group_id:
|
||||
referencedColumnName: id
|
||||
cascade: [ persist , detach, merge]
|
Loading…
x
Reference in New Issue
Block a user