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
ae7be288
Commit
ae7be288
authored
May 03, 2009
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] Work on single table inheritance with more functional tests.
parent
5a00a947
Changes
15
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
335 additions
and
149 deletions
+335
-149
NotifyPropertyChanged.php
lib/Doctrine/Common/NotifyPropertyChanged.php
+5
-0
AbstractPlatform.php
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
+1
-1
MySqlPlatform.php
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
+1
-1
SqlitePlatform.php
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
+1
-1
AbstractQuery.php
lib/Doctrine/ORM/AbstractQuery.php
+4
-9
AbstractHydrator.php
lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
+1
-0
ClassMetadata.php
lib/Doctrine/ORM/Mapping/ClassMetadata.php
+1
-1
NativeQuery.php
lib/Doctrine/ORM/NativeQuery.php
+2
-2
PersistentCollection.php
lib/Doctrine/ORM/PersistentCollection.php
+25
-15
SqlWalker.php
lib/Doctrine/ORM/Query/SqlWalker.php
+88
-16
SchemaTool.php
lib/Doctrine/ORM/Tools/SchemaTool.php
+76
-68
UnitOfWork.php
lib/Doctrine/ORM/UnitOfWork.php
+0
-4
SingleTableInheritanceTest.php
...trine/Tests/ORM/Functional/SingleTableInheritanceTest.php
+102
-3
DeleteSqlGenerationTest.php
tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php
+26
-26
UpdateSqlGenerationTest.php
tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php
+2
-2
No files found.
lib/Doctrine/Common/NotifyPropertyChanged.php
View file @
ae7be288
...
...
@@ -30,6 +30,11 @@ namespace Doctrine\Common;
*/
interface
NotifyPropertyChanged
{
/**
* Adds a listener that wants to be notified about property changes.
*
* @param PropertyChangedListener $listener
*/
public
function
addPropertyChangedListener
(
PropertyChangedListener
$listener
);
}
lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
View file @
ae7be288
...
...
@@ -1005,7 +1005,7 @@ abstract class AbstractPlatform
$queryFields
=
$this
->
getFieldDeclarationListSql
(
$columns
);
if
(
isset
(
$options
[
'primary'
])
&&
!
empty
(
$options
[
'primary'
]))
{
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
array_
values
(
$options
[
'primary'
]
))
.
')'
;
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
array_
unique
(
array_values
(
$options
[
'primary'
])
))
.
')'
;
}
if
(
isset
(
$options
[
'indexes'
])
&&
!
empty
(
$options
[
'indexes'
]))
{
...
...
lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
View file @
ae7be288
...
...
@@ -641,7 +641,7 @@ class MySqlPlatform extends AbstractPlatform
// attach all primary keys
if
(
isset
(
$options
[
'primary'
])
&&
!
empty
(
$options
[
'primary'
]))
{
$keyColumns
=
array_
values
(
$options
[
'primary'
]
);
$keyColumns
=
array_
unique
(
array_values
(
$options
[
'primary'
])
);
$keyColumns
=
array_map
(
array
(
$this
,
'quoteIdentifier'
),
$keyColumns
);
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
$keyColumns
)
.
')'
;
}
...
...
lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
View file @
ae7be288
...
...
@@ -504,7 +504,7 @@ class SqlitePlatform extends AbstractPlatform
}
if
(
!
$autoinc
&&
isset
(
$options
[
'primary'
])
&&
!
empty
(
$options
[
'primary'
]))
{
$keyColumns
=
array_
values
(
$options
[
'primary'
]
);
$keyColumns
=
array_
unique
(
array_values
(
$options
[
'primary'
])
);
$keyColumns
=
array_map
(
array
(
$this
,
'quoteIdentifier'
),
$keyColumns
);
$queryFields
.=
', PRIMARY KEY('
.
implode
(
', '
,
$keyColumns
)
.
')'
;
}
...
...
lib/Doctrine/ORM/AbstractQuery.php
View file @
ae7be288
...
...
@@ -131,11 +131,7 @@ abstract class AbstractQuery
}
/**
* Frees the resources used by the query object. It especially breaks a
* cyclic reference between the query object and it's parsers. This enables
* PHP's current GC to reclaim the memory.
* This method can therefore be used to reduce memory usage when creating a lot
* of query objects during a request.
* Frees the resources used by the query object.
*/
public
function
free
()
{
...
...
@@ -413,7 +409,7 @@ abstract class AbstractQuery
* Alias for getSingleResult(HYDRATE_SINGLE_SCALAR).
*
* @return mixed
* @throws QueryException
If the query result is not unique.
* @throws QueryException If the query result is not unique.
*/
public
function
getSingleScalarResult
()
{
...
...
@@ -462,9 +458,8 @@ abstract class AbstractQuery
/**
* Executes the query.
*
* @param string $params Parameters to be sent to query.
* @param integer $hydrationMode Doctrine processing mode to be used during hydration process.
* One of the Query::HYDRATE_* constants.
* @param string $params Any additional query parameters.
* @param integer $hydrationMode Processing mode to be used during the hydration process.
* @return mixed
*/
public
function
execute
(
$params
=
array
(),
$hydrationMode
=
null
)
...
...
lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
View file @
ae7be288
...
...
@@ -21,6 +21,7 @@
namespace
Doctrine\ORM\Internal\Hydration
;
use
Doctrine\Common\DoctrineException
;
use
\PDO
;
/**
...
...
lib/Doctrine/ORM/Mapping/ClassMetadata.php
View file @
ae7be288
...
...
@@ -869,7 +869,7 @@ final class ClassMetadata
*/
public
function
hasField
(
$fieldName
)
{
return
isset
(
$this
->
_
columnNam
es
[
$fieldName
]);
return
isset
(
$this
->
_
reflectionProperti
es
[
$fieldName
]);
}
/**
...
...
lib/Doctrine/ORM/NativeQuery.php
View file @
ae7be288
...
...
@@ -53,7 +53,7 @@ class NativeQuery extends AbstractQuery
}
/**
* Gets the SQL query
/queries that correspond to this DQL query
.
* Gets the SQL query.
*
* @return mixed The built sql query or an array of all sql queries.
* @override
...
...
@@ -64,7 +64,7 @@ class NativeQuery extends AbstractQuery
}
/**
* Execute
d
the query.
* Execute
s
the query.
*
* @param array $params
* @return Statement The Statement handle.
...
...
lib/Doctrine/ORM/PersistentCollection.php
View file @
ae7be288
...
...
@@ -21,6 +21,7 @@
namespace
Doctrine\ORM
;
use
Doctrine\Common\DoctrineException
;
use
Doctrine\ORM\Mapping\AssociationMapping
;
/**
...
...
@@ -127,7 +128,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
$this
->
_ownerClass
=
$em
->
getClassMetadata
(
$type
);
if
(
$keyField
!==
null
)
{
if
(
!
$this
->
_ownerClass
->
hasField
(
$keyField
))
{
\Doctrine\Common\
DoctrineException
::
updateMe
(
"Invalid field '
$keyField
' can't be used as key."
);
throw
DoctrineException
::
updateMe
(
"Invalid field '
$keyField
' can't be used as key."
);
}
$this
->
_keyField
=
$keyField
;
}
...
...
@@ -167,12 +168,12 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
$this
->
_owner
=
$entity
;
$this
->
_association
=
$assoc
;
if
(
$assoc
->
isInverseSide
())
{
// for sure bidirectional
// for sure bi
-
directional
$this
->
_backRefFieldName
=
$assoc
->
getMappedByFieldName
();
}
else
{
$targetClass
=
$this
->
_em
->
getClassMetadata
(
$assoc
->
getTargetEntityName
());
if
(
$targetClass
->
hasInverseAssociationMapping
(
$assoc
->
getSourceFieldName
()))
{
// bidirectional
// bi
-
directional
$this
->
_backRefFieldName
=
$targetClass
->
getInverseAssociationMapping
(
$assoc
->
getSourceFieldName
())
->
getSourceFieldName
();
}
...
...
@@ -240,7 +241,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
*
* @param mixed $value
* @param string $key
* @return
TRUE
* @return
boolean Always TRUE.
* @override
*/
public
function
add
(
$value
)
...
...
@@ -255,7 +256,6 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
->
setValue
(
$value
,
$this
->
_owner
);
}
}
else
{
//TODO: Register collection as dirty with the UoW if necessary
$this
->
_changed
();
}
...
...
@@ -263,7 +263,7 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
}
/**
* Adds all e
ntitie
s of the other collection to this collection.
* Adds all e
lement
s of the other collection to this collection.
*
* @param object $otherCollection
* @todo Impl
...
...
@@ -280,11 +280,13 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
/**
* INTERNAL:
* Sets a flag that indicates whether the collection is currently being hydrated.
* This has the following consequences:
*
* If the flag is set to TRUE, this has the following consequences:
*
* 1) During hydration, bidirectional associations are completed automatically
* by setting the back reference.
* 2) During hydration no change notifications are reported to the UnitOfWork.
*
I.e. t
hat means add() etc. do not cause the collection to be scheduled
*
T
hat means add() etc. do not cause the collection to be scheduled
* for an update.
*
* @param boolean $bool
...
...
@@ -295,11 +297,8 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
}
/**
* INTERNAL: Takes a snapshot from this collection.
*
* Snapshots are used for diff processing, for example
* when a fetched collection has three elements, then two of those
* are being removed the diff would contain one element.
* INTERNAL:
* Tells this collection to take a snapshot of its current state.
*/
public
function
takeSnapshot
()
{
...
...
@@ -385,12 +384,23 @@ final class PersistentCollection extends \Doctrine\Common\Collections\Collection
//$this->_em->getUnitOfWork()->scheduleCollectionUpdate($this);
}*/
}
/**
* Gets a boolean flag indicating whether this colleciton is dirty which means
* its state needs to be synchronized with the database.
*
* @return boolean TRUE if the collection is dirty, FALSE otherwise.
*/
public
function
isDirty
()
{
return
$this
->
_isDirty
;
}
/**
* Sets a boolean flag, indicating whether this collection is dirty.
*
* @param boolean $dirty Whether the collection should be marked dirty or not.
*/
public
function
setDirty
(
$dirty
)
{
$this
->
_isDirty
=
$dirty
;
...
...
lib/Doctrine/ORM/Query/SqlWalker.php
View file @
ae7be288
This diff is collapsed.
Click to expand it.
lib/Doctrine/ORM/Tools/SchemaTool.php
View file @
ae7be288
...
...
@@ -87,74 +87,11 @@ class SchemaTool
continue
;
}
$columns
=
$this
->
_gatherColumns
(
$class
);
// table columns
$options
=
array
();
// table options
$columns
=
$this
->
_gatherColumns
(
$class
,
$options
);
// table columns
foreach
(
$class
->
getAssociationMappings
()
as
$mapping
)
{
$foreignClass
=
$this
->
_em
->
getClassMetadata
(
$mapping
->
getTargetEntityName
());
if
(
$mapping
->
isOneToOne
()
&&
$mapping
->
isOwningSide
())
{
$constraint
=
array
();
$constraint
[
'tableName'
]
=
$class
->
getTableName
();
$constraint
[
'foreignTable'
]
=
$foreignClass
->
getTableName
();
$constraint
[
'local'
]
=
array
();
$constraint
[
'foreign'
]
=
array
();
foreach
(
$mapping
->
getJoinColumns
()
as
$joinColumn
)
{
$column
=
array
();
$column
[
'name'
]
=
$joinColumn
[
'name'
];
$column
[
'type'
]
=
$foreignClass
->
getTypeOfColumn
(
$joinColumn
[
'referencedColumnName'
]);
$columns
[
$joinColumn
[
'name'
]]
=
$column
;
$constraint
[
'local'
][]
=
$joinColumn
[
'name'
];
$constraint
[
'foreign'
][]
=
$joinColumn
[
'referencedColumnName'
];
}
$foreignKeyConstraints
[]
=
$constraint
;
}
else
if
(
$mapping
->
isOneToMany
()
&&
$mapping
->
isOwningSide
())
{
//... create join table, one-many through join table supported later
throw
DoctrineException
::
updateMe
(
"Not yet implemented."
);
}
else
if
(
$mapping
->
isManyToMany
()
&&
$mapping
->
isOwningSide
())
{
// create join table
$joinTableColumns
=
array
();
$joinTableOptions
=
array
();
$joinTable
=
$mapping
->
getJoinTable
();
$constraint1
=
array
();
$constraint1
[
'tableName'
]
=
$joinTable
[
'name'
];
$constraint1
[
'foreignTable'
]
=
$class
->
getTableName
();
$constraint1
[
'local'
]
=
array
();
$constraint1
[
'foreign'
]
=
array
();
foreach
(
$joinTable
[
'joinColumns'
]
as
$joinColumn
)
{
$column
=
array
();
$column
[
'primary'
]
=
true
;
$joinTableOptions
[
'primary'
][]
=
$joinColumn
[
'name'
];
$column
[
'name'
]
=
$joinColumn
[
'name'
];
$column
[
'type'
]
=
$class
->
getTypeOfColumn
(
$joinColumn
[
'referencedColumnName'
]);
$joinTableColumns
[
$joinColumn
[
'name'
]]
=
$column
;
$constraint1
[
'local'
][]
=
$joinColumn
[
'name'
];
$constraint1
[
'foreign'
][]
=
$joinColumn
[
'referencedColumnName'
];
}
$foreignKeyConstraints
[]
=
$constraint1
;
$constraint2
=
array
();
$constraint2
[
'tableName'
]
=
$joinTable
[
'name'
];
$constraint2
[
'foreignTable'
]
=
$foreignClass
->
getTableName
();
$constraint2
[
'local'
]
=
array
();
$constraint2
[
'foreign'
]
=
array
();
foreach
(
$joinTable
[
'inverseJoinColumns'
]
as
$inverseJoinColumn
)
{
$column
=
array
();
$column
[
'primary'
]
=
true
;
$joinTableOptions
[
'primary'
][]
=
$inverseJoinColumn
[
'name'
];
$column
[
'name'
]
=
$inverseJoinColumn
[
'name'
];
$column
[
'type'
]
=
$this
->
_em
->
getClassMetadata
(
$mapping
->
getTargetEntityName
())
->
getTypeOfColumn
(
$inverseJoinColumn
[
'referencedColumnName'
]);
$joinTableColumns
[
$inverseJoinColumn
[
'name'
]]
=
$column
;
$constraint2
[
'local'
][]
=
$inverseJoinColumn
[
'name'
];
$constraint2
[
'foreign'
][]
=
$inverseJoinColumn
[
'referencedColumnName'
];
}
$foreignKeyConstraints
[]
=
$constraint2
;
$sql
=
array_merge
(
$sql
,
$this
->
_platform
->
getCreateTableSql
(
$joinTable
[
'name'
],
$joinTableColumns
,
$joinTableOptions
));
}
}
$this
->
_gatherRelationsSql
(
$class
,
$sql
,
$columns
,
$foreignKeyConstraints
);
if
(
$class
->
isInheritanceTypeSingleTable
())
{
// Add the discriminator column
$discrColumnDef
=
$this
->
_getDiscriminatorColumnDefinition
(
$class
);
...
...
@@ -166,7 +103,9 @@ class SchemaTool
$processedClasses
[
$parentClassName
]
=
true
;
}
foreach
(
$class
->
getSubclasses
()
as
$subClassName
)
{
$columns
=
array_merge
(
$columns
,
$this
->
_gatherColumns
(
$this
->
_em
->
getClassMetadata
(
$subClassName
)));
$subClass
=
$this
->
_em
->
getClassMetadata
(
$subClassName
);
$columns
=
array_merge
(
$columns
,
$this
->
_gatherColumns
(
$subClass
,
$options
));
$this
->
_gatherRelationsSql
(
$subClass
,
$sql
,
$columns
,
$foreignKeyConstraints
);
$processedClasses
[
$subClassName
]
=
true
;
}
}
else
if
(
$class
->
isInheritanceTypeJoined
())
{
...
...
@@ -200,7 +139,7 @@ class SchemaTool
);
}
private
function
_gatherColumns
(
$class
)
private
function
_gatherColumns
(
$class
,
array
&
$options
)
{
$columns
=
array
();
foreach
(
$class
->
getFieldMappings
()
as
$fieldName
=>
$mapping
)
{
...
...
@@ -218,9 +157,78 @@ class SchemaTool
}
$columns
[
$mapping
[
'columnName'
]]
=
$column
;
}
return
$columns
;
}
private
function
_gatherRelationsSql
(
$class
,
array
&
$sql
,
array
&
$columns
,
array
&
$constraints
)
{
foreach
(
$class
->
getAssociationMappings
()
as
$mapping
)
{
$foreignClass
=
$this
->
_em
->
getClassMetadata
(
$mapping
->
getTargetEntityName
());
if
(
$mapping
->
isOneToOne
()
&&
$mapping
->
isOwningSide
())
{
$constraint
=
array
();
$constraint
[
'tableName'
]
=
$class
->
getTableName
();
$constraint
[
'foreignTable'
]
=
$foreignClass
->
getTableName
();
$constraint
[
'local'
]
=
array
();
$constraint
[
'foreign'
]
=
array
();
foreach
(
$mapping
->
getJoinColumns
()
as
$joinColumn
)
{
$column
=
array
();
$column
[
'name'
]
=
$joinColumn
[
'name'
];
$column
[
'type'
]
=
$foreignClass
->
getTypeOfColumn
(
$joinColumn
[
'referencedColumnName'
]);
$columns
[
$joinColumn
[
'name'
]]
=
$column
;
$constraint
[
'local'
][]
=
$joinColumn
[
'name'
];
$constraint
[
'foreign'
][]
=
$joinColumn
[
'referencedColumnName'
];
}
$constraints
[]
=
$constraint
;
}
else
if
(
$mapping
->
isOneToMany
()
&&
$mapping
->
isOwningSide
())
{
//... create join table, one-many through join table supported later
throw
DoctrineException
::
updateMe
(
"Not yet implemented."
);
}
else
if
(
$mapping
->
isManyToMany
()
&&
$mapping
->
isOwningSide
())
{
// create join table
$joinTableColumns
=
array
();
$joinTableOptions
=
array
();
$joinTable
=
$mapping
->
getJoinTable
();
$constraint1
=
array
();
$constraint1
[
'tableName'
]
=
$joinTable
[
'name'
];
$constraint1
[
'foreignTable'
]
=
$class
->
getTableName
();
$constraint1
[
'local'
]
=
array
();
$constraint1
[
'foreign'
]
=
array
();
foreach
(
$joinTable
[
'joinColumns'
]
as
$joinColumn
)
{
$column
=
array
();
$column
[
'primary'
]
=
true
;
$joinTableOptions
[
'primary'
][]
=
$joinColumn
[
'name'
];
$column
[
'name'
]
=
$joinColumn
[
'name'
];
$column
[
'type'
]
=
$class
->
getTypeOfColumn
(
$joinColumn
[
'referencedColumnName'
]);
$joinTableColumns
[
$joinColumn
[
'name'
]]
=
$column
;
$constraint1
[
'local'
][]
=
$joinColumn
[
'name'
];
$constraint1
[
'foreign'
][]
=
$joinColumn
[
'referencedColumnName'
];
}
$constraints
[]
=
$constraint1
;
$constraint2
=
array
();
$constraint2
[
'tableName'
]
=
$joinTable
[
'name'
];
$constraint2
[
'foreignTable'
]
=
$foreignClass
->
getTableName
();
$constraint2
[
'local'
]
=
array
();
$constraint2
[
'foreign'
]
=
array
();
foreach
(
$joinTable
[
'inverseJoinColumns'
]
as
$inverseJoinColumn
)
{
$column
=
array
();
$column
[
'primary'
]
=
true
;
$joinTableOptions
[
'primary'
][]
=
$inverseJoinColumn
[
'name'
];
$column
[
'name'
]
=
$inverseJoinColumn
[
'name'
];
$column
[
'type'
]
=
$this
->
_em
->
getClassMetadata
(
$mapping
->
getTargetEntityName
())
->
getTypeOfColumn
(
$inverseJoinColumn
[
'referencedColumnName'
]);
$joinTableColumns
[
$inverseJoinColumn
[
'name'
]]
=
$column
;
$constraint2
[
'local'
][]
=
$inverseJoinColumn
[
'name'
];
$constraint2
[
'foreign'
][]
=
$inverseJoinColumn
[
'referencedColumnName'
];
}
$constraints
[]
=
$constraint2
;
$sql
=
array_merge
(
$sql
,
$this
->
_platform
->
getCreateTableSql
(
$joinTable
[
'name'
],
$joinTableColumns
,
$joinTableOptions
));
}
}
}
public
function
dropSchema
(
array
$classes
)
{
//TODO
...
...
lib/Doctrine/ORM/UnitOfWork.php
View file @
ae7be288
...
...
@@ -333,10 +333,6 @@ class UnitOfWork implements PropertyChangedListener
$oid
=
spl_object_hash
(
$entity
);
$state
=
$this
->
getEntityState
(
$entity
);
if
(
$state
==
self
::
STATE_MANAGED
&&
(
$entity
instanceof
\Doctrine\Common\NotifyPropertyChanged
))
{
continue
;
// entity notifies us, no need to calculate changes
}
// Look for changes in the entity itself by comparing against the
// original data we have.
if
(
$state
==
self
::
STATE_MANAGED
||
$state
==
self
::
STATE_NEW
)
{
...
...
tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php
View file @
ae7be288
...
...
@@ -15,21 +15,28 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
parent
::
setUp
();
$this
->
_schemaTool
->
createSchema
(
array
(
$this
->
_em
->
getClassMetadata
(
'Doctrine\Tests\ORM\Functional\ParentEntity'
),
$this
->
_em
->
getClassMetadata
(
'Doctrine\Tests\ORM\Functional\ChildEntity'
)
$this
->
_em
->
getClassMetadata
(
'Doctrine\Tests\ORM\Functional\ChildEntity'
),
$this
->
_em
->
getClassMetadata
(
'Doctrine\Tests\ORM\Functional\RelatedEntity'
)
));
}
public
function
test
Insert
()
public
function
test
CRUD
()
{
$parent
=
new
ParentEntity
;
$parent
->
setData
(
'foobar'
);
$this
->
_em
->
save
(
$parent
);
$relatedEntity
=
new
RelatedEntity
;
$relatedEntity
->
setName
(
'theRelatedOne'
);
$this
->
_em
->
save
(
$relatedEntity
);
$child
=
new
ChildEntity
;
$child
->
setData
(
'thedata'
);
$child
->
setNumber
(
1234
);
$child
->
setRelatedEntity
(
$relatedEntity
);
$this
->
_em
->
save
(
$child
);
...
...
@@ -43,9 +50,45 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this
->
assertEquals
(
2
,
count
(
$entities
));
$this
->
assertTrue
(
$entities
[
0
]
instanceof
ParentEntity
);
$this
->
assertTrue
(
$entities
[
1
]
instanceof
ChildEntity
);
$this
->
assertTrue
(
is_numeric
(
$entities
[
0
]
->
getId
()));
$this
->
assertTrue
(
is_numeric
(
$entities
[
1
]
->
getId
()));
$this
->
assertEquals
(
'foobar'
,
$entities
[
0
]
->
getData
());
$this
->
assertEquals
(
'thedata'
,
$entities
[
1
]
->
getData
());
$this
->
assertEquals
(
1234
,
$entities
[
1
]
->
getNumber
());
$this
->
_em
->
clear
();
$query
=
$this
->
_em
->
createQuery
(
"select e from Doctrine\Tests\ORM\Functional\ChildEntity e"
);
$entities
=
$query
->
getResultList
();
$this
->
assertEquals
(
1
,
count
(
$entities
));
$this
->
assertTrue
(
$entities
[
0
]
instanceof
ChildEntity
);
$this
->
assertTrue
(
is_numeric
(
$entities
[
0
]
->
getId
()));
$this
->
assertEquals
(
'thedata'
,
$entities
[
0
]
->
getData
());
$this
->
assertEquals
(
1234
,
$entities
[
0
]
->
getNumber
());
$this
->
_em
->
clear
();
$query
=
$this
->
_em
->
createQuery
(
"select r,o from Doctrine\Tests\ORM\Functional\RelatedEntity r join r.owner o"
);
$entities
=
$query
->
getResultList
();
$this
->
assertEquals
(
1
,
count
(
$entities
));
$this
->
assertTrue
(
$entities
[
0
]
instanceof
RelatedEntity
);
$this
->
assertTrue
(
is_numeric
(
$entities
[
0
]
->
getId
()));
$this
->
assertEquals
(
'theRelatedOne'
,
$entities
[
0
]
->
getName
());
$this
->
assertTrue
(
$entities
[
0
]
->
getOwner
()
instanceof
ChildEntity
);
$this
->
assertEquals
(
'thedata'
,
$entities
[
0
]
->
getOwner
()
->
getData
());
$this
->
assertSame
(
$entities
[
0
],
$entities
[
0
]
->
getOwner
()
->
getRelatedEntity
());
$query
=
$this
->
_em
->
createQuery
(
"update Doctrine\Tests\ORM\Functional\ChildEntity e set e.data = 'newdata'"
);
$affected
=
$query
->
execute
();
$this
->
assertEquals
(
1
,
$affected
);
$query
=
$this
->
_em
->
createQuery
(
"delete Doctrine\Tests\ORM\Functional\ParentEntity e"
);
$affected
=
$query
->
execute
();
$this
->
assertEquals
(
2
,
$affected
);
}
}
...
...
@@ -91,6 +134,11 @@ class ChildEntity extends ParentEntity {
* @DoctrineColumn(type="integer", nullable=true)
*/
private
$number
;
/**
* @DoctrineOneToOne(targetEntity="RelatedEntity")
* @DoctrineJoinColumn(name="related_entity_id", referencedColumnName="id")
*/
private
$relatedEntity
;
public
function
getNumber
()
{
return
$this
->
number
;
...
...
@@ -99,5 +147,56 @@ class ChildEntity extends ParentEntity {
public
function
setNumber
(
$number
)
{
$this
->
number
=
$number
;
}
public
function
getRelatedEntity
()
{
return
$this
->
relatedEntity
;
}
public
function
setRelatedEntity
(
$relatedEntity
)
{
$this
->
relatedEntity
=
$relatedEntity
;
$relatedEntity
->
setOwner
(
$this
);
}
}
/**
* @DoctrineEntity
*/
class
RelatedEntity
{
/**
* @DoctrineId
* @DoctrineColumn(type="integer")
* @DoctrineGeneratedValue(strategy="auto")
*/
private
$id
;
/**
* @DoctrineColumn(type="varchar", length=50)
*/
private
$name
;
/**
* @DoctrineOneToOne(targetEntity="ChildEntity", mappedBy="relatedEntity")
*/
private
$owner
;
public
function
getId
()
{
return
$this
->
id
;
}
public
function
getName
()
{
return
$this
->
name
;
}
public
function
setName
(
$name
)
{
$this
->
name
=
$name
;
}
public
function
getOwner
()
{
return
$this
->
owner
;
}
public
function
setOwner
(
$owner
)
{
$this
->
owner
=
$owner
;
if
(
$owner
->
getRelatedEntity
()
!==
$this
)
{
$owner
->
setRelatedEntity
(
$this
);
}
}
}
tests/Doctrine/Tests/ORM/Query/DeleteSqlGenerationTest.php
View file @
ae7be288
...
...
@@ -60,11 +60,11 @@ class DeleteSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{
$this
->
assertSqlGeneration
(
'DELETE Doctrine\Tests\Models\CMS\CmsUser u'
,
'DELETE FROM cms_users
c0_
'
'DELETE FROM cms_users'
);
$this
->
assertSqlGeneration
(
'DELETE FROM Doctrine\Tests\Models\CMS\CmsUser u'
,
'DELETE FROM cms_users
c0_
'
'DELETE FROM cms_users'
);
}
...
...
@@ -72,7 +72,7 @@ class DeleteSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{
$this
->
assertSqlGeneration
(
'DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1'
,
'DELETE FROM cms_users
c0_ WHERE c0_.
id = ?'
'DELETE FROM cms_users
WHERE
id = ?'
);
}
...
...
@@ -80,12 +80,12 @@ class DeleteSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{
$this
->
assertSqlGeneration
(
'DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = ?1 OR u.name = ?2'
,
'DELETE FROM cms_users
c0_ WHERE c0_.username = ? OR c0_.
name = ?'
'DELETE FROM cms_users
WHERE username = ? OR
name = ?'
);
$this
->
assertSqlGeneration
(
'DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1 OR ( u.username = ?2 OR u.name = ?3)'
,
'DELETE FROM cms_users
c0_ WHERE c0_.id = ? OR (c0_.username = ? OR c0_.
name = ?)'
'DELETE FROM cms_users
WHERE id = ? OR (username = ? OR
name = ?)'
);
//$this->assertSqlGeneration(
...
...
@@ -98,7 +98,7 @@ class DeleteSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{
$this
->
assertSqlGeneration
(
"delete from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1"
,
"DELETE FROM cms_users
c0_ WHERE c0_.
username = ?"
"DELETE FROM cms_users
WHERE
username = ?"
);
}
...
...
@@ -106,7 +106,7 @@ class DeleteSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{
$this
->
assertSqlGeneration
(
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = ?1 AND u.name = ?2"
,
"DELETE FROM cms_users
c0_ WHERE c0_.username = ? AND c0_.
name = ?"
"DELETE FROM cms_users
WHERE username = ? AND
name = ?"
);
}
...
...
@@ -114,17 +114,17 @@ class DeleteSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{
$this
->
assertSqlGeneration
(
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE NOT u.id != ?1"
,
"DELETE FROM cms_users
c0_ WHERE NOT c0_.
id <> ?"
"DELETE FROM cms_users
WHERE NOT
id <> ?"
);
$this
->
assertSqlGeneration
(
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE NOT ( u.id != ?1 )"
,
"DELETE FROM cms_users
c0_ WHERE NOT (c0_.
id <> ?)"
"DELETE FROM cms_users
WHERE NOT (
id <> ?)"
);
$this
->
assertSqlGeneration
(
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE NOT ( u.id != ?1 AND u.username = ?2 )"
,
"DELETE FROM cms_users
c0_ WHERE NOT (c0_.id <> ? AND c0_.
username = ?)"
"DELETE FROM cms_users
WHERE NOT (id <> ? AND
username = ?)"
);
}
...
...
@@ -135,32 +135,32 @@ class DeleteSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
// id = ? was already tested (see testDeleteWithWhere())
$this
->
assertSqlGeneration
(
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id > ?1"
,
"DELETE FROM cms_users
c0_ WHERE c0_.
id > ?"
"DELETE FROM cms_users
WHERE
id > ?"
);
$this
->
assertSqlGeneration
(
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id >= ?1"
,
"DELETE FROM cms_users
c0_ WHERE c0_.
id >= ?"
"DELETE FROM cms_users
WHERE
id >= ?"
);
$this
->
assertSqlGeneration
(
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id < ?1"
,
"DELETE FROM cms_users
c0_ WHERE c0_.
id < ?"
"DELETE FROM cms_users
WHERE
id < ?"
);
$this
->
assertSqlGeneration
(
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id <= ?1"
,
"DELETE FROM cms_users
c0_ WHERE c0_.
id <= ?"
"DELETE FROM cms_users
WHERE
id <= ?"
);
$this
->
assertSqlGeneration
(
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id <> ?1"
,
"DELETE FROM cms_users
c0_ WHERE c0_.
id <> ?"
"DELETE FROM cms_users
WHERE
id <> ?"
);
$this
->
assertSqlGeneration
(
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id != ?1"
,
"DELETE FROM cms_users
c0_ WHERE c0_.
id <> ?"
"DELETE FROM cms_users
WHERE
id <> ?"
);
}
...
...
@@ -168,12 +168,12 @@ class DeleteSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{
$this
->
assertSqlGeneration
(
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id NOT BETWEEN ?1 AND ?2"
,
"DELETE FROM cms_users
c0_ WHERE c0_.
id NOT BETWEEN ? AND ?"
"DELETE FROM cms_users
WHERE
id NOT BETWEEN ? AND ?"
);
$this
->
assertSqlGeneration
(
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id BETWEEN ?1 AND ?2 AND u.username != ?3"
,
"DELETE FROM cms_users
c0_ WHERE c0_.id BETWEEN ? AND ? AND c0_.
username <> ?"
"DELETE FROM cms_users
WHERE id BETWEEN ? AND ? AND
username <> ?"
);
}
...
...
@@ -182,12 +182,12 @@ class DeleteSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
// "WHERE" Expression LikeExpression
$this
->
assertSqlGeneration
(
'DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username NOT LIKE ?1'
,
'DELETE FROM cms_users
c0_ WHERE c0_.
username NOT LIKE ?'
'DELETE FROM cms_users
WHERE
username NOT LIKE ?'
);
$this
->
assertSqlGeneration
(
"DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username LIKE ?1 ESCAPE '
\\
'"
,
"DELETE FROM cms_users
c0_ WHERE c0_.
username LIKE ? ESCAPE '
\\
'"
"DELETE FROM cms_users
WHERE
username LIKE ? ESCAPE '
\\
'"
);
}
...
...
@@ -196,12 +196,12 @@ class DeleteSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
// "WHERE" Expression NullComparisonExpression
$this
->
assertSqlGeneration
(
'DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IS NULL'
,
'DELETE FROM cms_users
c0_ WHERE c0_.
name IS NULL'
'DELETE FROM cms_users
WHERE
name IS NULL'
);
$this
->
assertSqlGeneration
(
'DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.name IS NOT NULL'
,
'DELETE FROM cms_users
c0_ WHERE c0_.
name IS NOT NULL'
'DELETE FROM cms_users
WHERE
name IS NOT NULL'
);
}
...
...
@@ -209,12 +209,12 @@ class DeleteSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{
$this
->
assertSqlGeneration
(
'DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE 1 = 1'
,
'DELETE FROM cms_users
c0_
WHERE 1 = 1'
'DELETE FROM cms_users WHERE 1 = 1'
);
$this
->
assertSqlGeneration
(
'DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE ?1 = 1'
,
'DELETE FROM cms_users
c0_
WHERE ? = 1'
'DELETE FROM cms_users WHERE ? = 1'
);
}
...
...
@@ -222,12 +222,12 @@ class DeleteSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{
$this
->
assertSqlGeneration
(
'DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id IN ( ?1, ?2, ?3, ?4 )'
,
'DELETE FROM cms_users
c0_ WHERE c0_.
id IN (?, ?, ?, ?)'
'DELETE FROM cms_users
WHERE
id IN (?, ?, ?, ?)'
);
$this
->
assertSqlGeneration
(
'DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id NOT IN ( ?1, ?2 )'
,
'DELETE FROM cms_users
c0_ WHERE c0_.
id NOT IN (?, ?)'
'DELETE FROM cms_users
WHERE
id NOT IN (?, ?)'
);
}
...
...
tests/Doctrine/Tests/ORM/Query/UpdateSqlGenerationTest.php
View file @
ae7be288
...
...
@@ -60,11 +60,11 @@ class UpdateSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
{
$this
->
assertSqlGeneration
(
'UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.name = ?1'
,
'UPDATE cms_users
c0_ SET c0_.
name = ?'
'UPDATE cms_users
SET
name = ?'
);
$this
->
assertSqlGeneration
(
'UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.name = ?1, u.username = ?2'
,
'UPDATE cms_users
c0_ SET c0_.name = ?, c0_.
username = ?'
'UPDATE cms_users
SET name = ?,
username = ?'
);
}
...
...
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