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
a0d26a84
Commit
a0d26a84
authored
Dec 05, 2009
by
beberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] DDC-169 - Fixed DatabaseDriver
parent
ecfa0eee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
25 deletions
+50
-25
DatabaseDriver.php
lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php
+2
-2
DatabaseDriverTest.php
tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php
+48
-23
No files found.
lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php
View file @
a0d26a84
...
...
@@ -82,7 +82,7 @@ class DatabaseDriver implements Driver
foreach
(
$columns
as
$column
)
{
// Skip columns that are foreign keys
foreach
(
$foreignKeys
as
$foreignKey
)
{
if
(
in_array
(
$column
->
getName
(),
$foreignKey
->
getColumns
(
)))
{
if
(
in_array
(
strtolower
(
$column
->
getName
()),
array_map
(
'strtolower'
,
$foreignKey
->
getColumns
()
)))
{
continue
(
2
);
}
}
...
...
@@ -142,7 +142,7 @@ class DatabaseDriver implements Driver
$foreignColumn
=
current
(
$foreignKey
->
getForeignColumns
());
$associationMapping
=
array
();
$associationMapping
[
'fieldName'
]
=
Inflector
::
camelize
(
str_replace
(
'_id'
,
''
,
$localColumn
));
$associationMapping
[
'fieldName'
]
=
Inflector
::
camelize
(
str_
i
replace
(
'_id'
,
''
,
$localColumn
));
$associationMapping
[
'columnName'
]
=
$localColumn
;
$associationMapping
[
'targetEntity'
]
=
Inflector
::
classify
(
$foreignKey
->
getForeignTableName
());
$associationMapping
[
'joinColumns'
][]
=
array
(
...
...
tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php
View file @
a0d26a84
...
...
@@ -29,25 +29,21 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this
->
_sm
->
dropAndCreateTable
(
$table
);
$this
->
assertClassMetadataYamlEqualsFile
(
__DIR__
.
"/DatabaseDriver/simpleYaml.yml"
,
"DbdriverFoo"
);
}
protected
function
assertClassMetadataYamlEqualsFile
(
$file
,
$className
)
{
$cm
=
new
ClassMetadataExporter
();
$cm
->
addMappingSource
(
$this
->
_sm
,
'database'
);
$exporter
=
$cm
->
getExporter
(
'yaml'
);
$metadatas
=
$cm
->
getMetadatasForMappingSources
();
$output
=
false
;
foreach
(
$metadatas
AS
$metadata
)
{
if
(
$metadata
->
name
==
$className
)
{
$output
=
$exporter
->
exportClassMetadata
(
$metadata
);
}
}
$this
->
assertTrue
(
$output
!==
false
,
"No class matching the name '"
.
$className
.
"' was found!"
);
$this
->
assertEquals
(
strtolower
(
trim
(
file_get_contents
(
$file
))),
strtolower
(
trim
(
$output
)));
$metadata
=
$this
->
extractClassMetadata
(
"DbdriverFoo"
);
$this
->
assertArrayHasKey
(
'id'
,
$metadata
->
fieldMappings
);
$this
->
assertEquals
(
'id'
,
$metadata
->
fieldMappings
[
'id'
][
'fieldName'
]);
$this
->
assertEquals
(
'id'
,
strtolower
(
$metadata
->
fieldMappings
[
'id'
][
'columnName'
]));
$this
->
assertEquals
(
'integer'
,
(
string
)
$metadata
->
fieldMappings
[
'id'
][
'type'
]);
$this
->
assertEquals
(
''
,
$metadata
->
fieldMappings
[
'id'
][
'default'
]);
$this
->
assertTrue
(
$metadata
->
fieldMappings
[
'id'
][
'notnull'
]);
$this
->
assertArrayHasKey
(
'bar'
,
$metadata
->
fieldMappings
);
$this
->
assertEquals
(
'bar'
,
$metadata
->
fieldMappings
[
'bar'
][
'fieldName'
]);
$this
->
assertEquals
(
'bar'
,
strtolower
(
$metadata
->
fieldMappings
[
'bar'
][
'columnName'
]));
$this
->
assertEquals
(
'string'
,
(
string
)
$metadata
->
fieldMappings
[
'bar'
][
'type'
]);
$this
->
assertEquals
(
200
,
$metadata
->
fieldMappings
[
'bar'
][
'length'
]);
$this
->
assertTrue
(
$metadata
->
fieldMappings
[
'bar'
][
'notnull'
]);
}
public
function
testCreateYamlWithForeignKeyFromDatabase
()
...
...
@@ -60,8 +56,7 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
$tableB
->
createColumn
(
'id'
,
'integer'
);
$tableB
->
setPrimaryKey
(
array
(
'id'
));
$sm
=
$this
->
_em
->
getConnection
()
->
getSchemaManager
();
$sm
->
dropAndCreateTable
(
$tableB
);
$this
->
_sm
->
dropAndCreateTable
(
$tableB
);
$tableA
=
new
\Doctrine\DBAL\Schema\Table
(
"dbdriver_baz"
);
$tableA
->
createColumn
(
'id'
,
'integer'
);
...
...
@@ -69,9 +64,39 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase
$tableA
->
createColumn
(
'bar_id'
,
'integer'
);
$tableA
->
addForeignKeyConstraint
(
'dbdriver_bar'
,
array
(
'bar_id'
),
array
(
'id'
));
$this
->
_sm
=
$this
->
_em
->
getConnection
()
->
getSchemaManager
();
$this
->
_sm
->
dropAndCreateTable
(
$tableA
);
$this
->
assertClassMetadataYamlEqualsFile
(
__DIR__
.
"/DatabaseDriver/fkYaml.yml"
,
"DbdriverBaz"
);
$metadata
=
$this
->
extractClassMetadata
(
"DbdriverBaz"
);
$this
->
assertArrayNotHasKey
(
'bar'
,
$metadata
->
fieldMappings
);
$this
->
assertArrayHasKey
(
'id'
,
$metadata
->
fieldMappings
);
$metadata
->
associationMappings
=
\array_change_key_case
(
$metadata
->
associationMappings
,
\CASE_LOWER
);
$this
->
assertArrayHasKey
(
'bar'
,
$metadata
->
associationMappings
);
$this
->
assertType
(
'Doctrine\ORM\Mapping\OneToOneMapping'
,
$metadata
->
associationMappings
[
'bar'
]);
}
/**
*
* @param string $className
* @return ClassMetadata
*/
protected
function
extractClassMetadata
(
$className
)
{
$cm
=
new
ClassMetadataExporter
();
$cm
->
addMappingSource
(
$this
->
_sm
,
'database'
);
$exporter
=
$cm
->
getExporter
(
'yaml'
);
$metadatas
=
$cm
->
getMetadatasForMappingSources
();
$output
=
false
;
foreach
(
$metadatas
AS
$metadata
)
{
if
(
$metadata
->
name
==
$className
)
{
return
$metadata
;
}
}
$this
->
fail
(
"No class matching the name '"
.
$className
.
"' was found!"
);
}
}
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