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
4bec3e2c
Commit
4bec3e2c
authored
Jan 22, 2010
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0][DDC-263] Fixed. Patch provided by Christian Heinrich.
parent
c4549c45
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
54 additions
and
60 deletions
+54
-60
Collection.php
lib/Doctrine/Common/Collections/Collection.php
+3
-4
AssociationMapping.php
lib/Doctrine/ORM/Mapping/AssociationMapping.php
+14
-3
XmlDriver.php
lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
+8
-17
YamlDriver.php
lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php
+4
-33
MappingDriverTest.php
tests/Doctrine/Tests/ORM/Mapping/MappingDriverTest.php
+12
-0
Doctrine.Tests.ORM.Mapping.User.dcm.xml
...s/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml
+7
-1
Doctrine.Tests.ORM.Mapping.User.dcm.yml
.../ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml
+4
-1
index.php
tools/sandbox/index.php
+2
-1
No files found.
lib/Doctrine/Common/Collections/Collection.php
View file @
4bec3e2c
...
...
@@ -22,7 +22,7 @@
namespace
Doctrine\Common\Collections
;
/**
* The missing (SPL) Collection/Array interface.
* The missing (SPL) Collection/Array
/OrderedMap
interface.
*
* A Collection resembles the nature of a regular PHP array. That is,
* it is essentially an ordered map that can syntactically also be used
...
...
@@ -31,7 +31,7 @@ namespace Doctrine\Common\Collections;
* A Collection has an internal iterator just like a PHP array. In addition
* a Collection can be iterated with external iterators, which is preferrable.
* To use an external iterator simply use the foreach language construct to
* iterat
or over the collection (which cann
s getIterator() internally) or
* iterat
e over the collection (which call
s getIterator() internally) or
* explicitly retrieve an iterator though getIterator() which can then be
* used to iterate over the collection.
*
...
...
@@ -58,8 +58,7 @@ interface Collection extends \Countable, \IteratorAggregate, \ArrayAccess
function
add
(
$element
);
/**
* Clears the collection.
*
* Clears the collection, removing all elements.
*/
function
clear
();
...
...
lib/Doctrine/ORM/Mapping/AssociationMapping.php
View file @
4bec3e2c
...
...
@@ -167,11 +167,22 @@ abstract class AssociationMapping
$this
->
fetchMode
=
isset
(
$mapping
[
'fetch'
])
?
$mapping
[
'fetch'
]
:
self
::
FETCH_LAZY
;
$cascades
=
isset
(
$mapping
[
'cascade'
])
?
$mapping
[
'cascade'
]
:
array
();
$this
->
isCascadeRemove
=
in_array
(
'remove'
,
$cascades
);
if
(
in_array
(
'all'
,
$cascades
))
{
$cascades
=
array
(
'remove'
,
'persist'
,
'refresh'
,
'merge'
,
'detach'
);
}
$this
->
isCascadeRemove
=
in_array
(
'remove'
,
$cascades
);
$this
->
isCascadePersist
=
in_array
(
'persist'
,
$cascades
);
$this
->
isCascadeRefresh
=
in_array
(
'refresh'
,
$cascades
);
$this
->
isCascadeMerge
=
in_array
(
'merge'
,
$cascades
);
$this
->
isCascadeDetach
=
in_array
(
'detach'
,
$cascades
);
$this
->
isCascadeMerge
=
in_array
(
'merge'
,
$cascades
);
$this
->
isCascadeDetach
=
in_array
(
'detach'
,
$cascades
);
}
/**
...
...
lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php
View file @
4bec3e2c
...
...
@@ -232,7 +232,7 @@ class XmlDriver extends AbstractFileDriver
if
(
isset
(
$oneToOneElement
->
cascade
))
{
$mapping
[
'cascade'
]
=
$this
->
_getCascadeMappings
(
$oneToOneElement
->
cascade
);
}
if
(
isset
(
$oneToOneElement
->
{
'orphan-removal'
}))
{
$mapping
[
'orphanRemoval'
]
=
(
bool
)
$oneToOneElement
->
{
'orphan-removal'
};
}
...
...
@@ -434,23 +434,14 @@ class XmlDriver extends AbstractFileDriver
private
function
_getCascadeMappings
(
$cascadeElement
)
{
$cascades
=
array
();
if
(
isset
(
$cascadeElement
->
{
'cascade-persist'
}))
{
$cascades
[]
=
'persist'
;
}
if
(
isset
(
$cascadeElement
->
{
'cascade-remove'
}))
{
$cascades
[]
=
'remove'
;
foreach
(
$cascadeElement
->
children
()
as
$action
)
{
// According to the JPA specifications, XML uses "cascade-persist"
// instead of "persist". Here, both variations
// are supported because both YAML and Annotation use "persist"
// and we want to make sure that this driver doesn't need to know
// anything about the supported cascading actions
$cascades
[]
=
str_replace
(
'cascade-'
,
''
,
$action
->
getName
())
;
}
if
(
isset
(
$cascadeElement
->
{
'cascade-merge'
}))
{
$cascades
[]
=
'merge'
;
}
if
(
isset
(
$cascadeElement
->
{
'cascade-refresh'
}))
{
$cascades
[]
=
'refresh'
;
}
return
$cascades
;
}
}
\ No newline at end of file
lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php
View file @
4bec3e2c
...
...
@@ -247,7 +247,7 @@ class YamlDriver extends AbstractFileDriver
}
if
(
isset
(
$oneToOneElement
[
'cascade'
]))
{
$mapping
[
'cascade'
]
=
$
this
->
_getCascadeMappings
(
$oneToOneElement
[
'cascade'
])
;
$mapping
[
'cascade'
]
=
$
oneToOneElement
[
'cascade'
]
;
}
$metadata
->
mapOneToOne
(
$mapping
);
...
...
@@ -268,7 +268,7 @@ class YamlDriver extends AbstractFileDriver
}
if
(
isset
(
$oneToManyElement
[
'cascade'
]))
{
$mapping
[
'cascade'
]
=
$
this
->
_getCascadeMappings
(
$oneToManyElement
[
'cascade'
])
;
$mapping
[
'cascade'
]
=
$
oneToManyElement
[
'cascade'
]
;
}
$metadata
->
mapOneToMany
(
$mapping
);
...
...
@@ -306,7 +306,7 @@ class YamlDriver extends AbstractFileDriver
$mapping
[
'joinColumns'
]
=
$joinColumns
;
if
(
isset
(
$manyToOneElement
[
'cascade'
]))
{
$mapping
[
'cascade'
]
=
$
this
->
_getCascadeMappings
(
$manyToOneElement
[
'cascade'
])
;
$mapping
[
'cascade'
]
=
$
manyToOneElement
[
'cascade'
]
;
}
$metadata
->
mapManyToOne
(
$mapping
);
...
...
@@ -359,7 +359,7 @@ class YamlDriver extends AbstractFileDriver
}
if
(
isset
(
$manyToManyElement
[
'cascade'
]))
{
$mapping
[
'cascade'
]
=
$
this
->
_getCascadeMappings
(
$manyToManyElement
[
'cascade'
])
;
$mapping
[
'cascade'
]
=
$
manyToManyElement
[
'cascade'
]
;
}
$metadata
->
mapManyToMany
(
$mapping
);
...
...
@@ -411,35 +411,6 @@ class YamlDriver extends AbstractFileDriver
return
$joinColumn
;
}
/**
* Gathers a list of cascade options found in the given cascade element.
*
* @param $cascadeElement The cascade element.
* @return array The list of cascade options.
*/
private
function
_getCascadeMappings
(
$cascadeElement
)
{
$cascades
=
array
();
if
(
isset
(
$cascadeElement
[
'cascadePersist'
]))
{
$cascades
[]
=
'persist'
;
}
if
(
isset
(
$cascadeElement
[
'cascadeRemove'
]))
{
$cascades
[]
=
'remove'
;
}
if
(
isset
(
$cascadeElement
[
'cascadeMerge'
]))
{
$cascades
[]
=
'merge'
;
}
if
(
isset
(
$cascadeElement
[
'cascadeRefresh'
]))
{
$cascades
[]
=
'refresh'
;
}
return
$cascades
;
}
/**
* Loads a mapping file with the given name and returns a map
* from class/entity names to their corresponding elements.
...
...
tests/Doctrine/Tests/ORM/Mapping/MappingDriverTest.php
View file @
4bec3e2c
...
...
@@ -67,6 +67,12 @@ class MappingDriverTest extends \Doctrine\Tests\OrmTestCase
$this
->
assertTrue
(
$class
->
associationMappings
[
'address'
]
instanceof
\Doctrine\ORM\Mapping\OneToOneMapping
);
$this
->
assertTrue
(
isset
(
$class
->
associationMappings
[
'address'
]));
$this
->
assertTrue
(
$class
->
associationMappings
[
'address'
]
->
isOwningSide
);
// Check cascading
$this
->
assertTrue
(
$class
->
associationMappings
[
'address'
]
->
isCascadeRemove
);
$this
->
assertFalse
(
$class
->
associationMappings
[
'address'
]
->
isCascadePersist
);
$this
->
assertFalse
(
$class
->
associationMappings
[
'address'
]
->
isCascadeRefresh
);
$this
->
assertFalse
(
$class
->
associationMappings
[
'address'
]
->
isCascadeDetach
);
$this
->
assertFalse
(
$class
->
associationMappings
[
'address'
]
->
isCascadeMerge
);
$this
->
assertTrue
(
$class
->
associationMappings
[
'phonenumbers'
]
instanceof
\Doctrine\ORM\Mapping\OneToManyMapping
);
$this
->
assertTrue
(
isset
(
$class
->
associationMappings
[
'phonenumbers'
]));
...
...
@@ -80,6 +86,12 @@ class MappingDriverTest extends \Doctrine\Tests\OrmTestCase
$this
->
assertEquals
(
count
(
$class
->
lifecycleCallbacks
),
2
);
$this
->
assertEquals
(
$class
->
lifecycleCallbacks
[
'prePersist'
][
0
],
'doStuffOnPrePersist'
);
$this
->
assertEquals
(
$class
->
lifecycleCallbacks
[
'postPersist'
][
0
],
'doStuffOnPostPersist'
);
// Make sure that cascade-all works as expected
$this
->
assertTrue
(
$class
->
associationMappings
[
'groups'
]
->
isCascadeRemove
);
$this
->
assertTrue
(
$class
->
associationMappings
[
'groups'
]
->
isCascadePersist
);
$this
->
assertTrue
(
$class
->
associationMappings
[
'groups'
]
->
isCascadeRefresh
);
$this
->
assertTrue
(
$class
->
associationMappings
[
'groups'
]
->
isCascadeDetach
);
$this
->
assertTrue
(
$class
->
associationMappings
[
'groups'
]
->
isCascadeMerge
);
}
}
...
...
tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml
View file @
4bec3e2c
...
...
@@ -20,6 +20,9 @@
<one-to-one
field=
"address"
target-entity=
"Address"
>
<join-column
name=
"address_id"
referenced-column-name=
"id"
/>
<cascade>
<cascade-remove
/>
</cascade>
</one-to-one>
<one-to-many
field=
"phonenumbers"
target-entity=
"Phonenumber"
mapped-by=
"user"
>
...
...
@@ -37,8 +40,11 @@
<join-column
name=
"group_id"
referenced-column-name=
"id"
/>
</inverse-join-columns>
</join-table>
<cascade>
<cascade-all/>
</cascade>
</many-to-many>
</entity>
</doctrine-mapping>
\ No newline at end of file
</doctrine-mapping>
tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml
View file @
4bec3e2c
...
...
@@ -16,11 +16,12 @@ Doctrine\Tests\ORM\Mapping\User:
joinColumn
:
name
:
address_id
referencedColumnName
:
id
cascade
:
[
remove
]
oneToMany
:
phonenumbers
:
targetEntity
:
Phonenumber
mappedBy
:
user
cascade
:
cascadePersist
cascade
:
[
persist
]
manyToMany
:
groups
:
targetEntity
:
Group
...
...
@@ -32,6 +33,8 @@ Doctrine\Tests\ORM\Mapping\User:
inverseJoinColumns
:
group_id
:
referencedColumnName
:
id
cascade
:
-
all
lifecycleCallbacks
:
doStuffOnPrePersist
:
prePersist
doStuffOnPostPersist
:
postPersist
\ No newline at end of file
tools/sandbox/index.php
View file @
4bec3e2c
...
...
@@ -50,4 +50,5 @@ $em = EntityManager::create($connectionOptions, $config);
$user
=
new
User
;
$address
=
new
Address
;
echo
'Hello World!'
.
PHP_EOL
;
\ No newline at end of file
echo
'Hello World!'
.
PHP_EOL
;
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