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
966450d4
Commit
966450d4
authored
Oct 08, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #154, has* relations should act as owns* when saving related objects
parent
11206fe5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
54 deletions
+42
-54
Connection.php
lib/Doctrine/Connection.php
+37
-46
Record.php
lib/Doctrine/Record.php
+5
-8
No files found.
lib/Doctrine/Connection.php
View file @
966450d4
...
...
@@ -521,66 +521,57 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$alias
=
$this
->
table
->
getAlias
(
$name
);
if
(
$rel
instanceof
Doctrine_Relation_Association
)
{
switch
(
$rel
->
getType
())
:
case
Doctrine_Relation
::
MANY_COMPOSITE
:
break
;
case
Doctrine_Relation
::
MANY_AGGREGATE
:
$asf
=
$rel
->
getAssociationFactory
();
if
(
$record
->
hasReference
(
$alias
))
{
$asf
=
$rel
->
getAssociationFactory
();
$new
=
$record
->
getReference
(
$alias
);
if
(
$record
->
hasReference
(
$alias
))
{
if
(
!
$this
->
hasOriginalsFor
(
$alias
))
{
$record
->
loadReference
(
$alias
);
}
$new
=
$record
->
getReference
(
$alias
);
$operations
=
Doctrine_Relation
::
getDeleteOperations
(
$this
->
originals
[
$alias
],
$new
);
if
(
!
$this
->
hasOriginalsFor
(
$alias
))
$record
->
loadReference
(
$alias
);
foreach
(
$operations
as
$r
)
{
$query
=
"DELETE FROM "
.
$asf
->
getTableName
()
.
" WHERE "
.
$fk
->
getForeign
()
.
" = ?"
$operations
=
Doctrine_Relation
::
getDeleteOperations
(
$this
->
originals
[
$alias
],
$new
);
foreach
(
$operations
as
$r
)
{
$query
=
"DELETE FROM "
.
$asf
->
getTableName
()
.
" WHERE "
.
$fk
->
getForeign
()
.
" = ?"
.
" AND "
.
$fk
->
getLocal
()
.
" = ?"
;
$this
->
table
->
getConnection
()
->
execute
(
$query
,
array
(
$r
->
getIncremented
(),
$record
->
getIncremented
()));
}
$operations
=
Doctrine_Relation
::
getInsertOperations
(
$this
->
originals
[
$alias
],
$new
);
foreach
(
$operations
as
$r
)
{
$reldao
=
$asf
->
create
();
$reldao
->
set
(
$fk
->
getForeign
(),
$r
);
$reldao
->
set
(
$fk
->
getLocal
(),
$this
);
$reldao
->
save
();
}
$this
->
originals
[
$alias
]
=
clone
$this
->
references
[
$alias
];
}
break
;
endswitch
;
$this
->
table
->
getConnection
()
->
execute
(
$query
,
array
(
$r
->
getIncremented
(),
$record
->
getIncremented
()));
}
$operations
=
Doctrine_Relation
::
getInsertOperations
(
$this
->
originals
[
$alias
],
$new
);
foreach
(
$operations
as
$r
)
{
$reldao
=
$asf
->
create
();
$reldao
->
set
(
$fk
->
getForeign
(),
$r
);
$reldao
->
set
(
$fk
->
getLocal
(),
$this
);
$reldao
->
save
();
}
$this
->
originals
[
$alias
]
=
clone
$this
->
references
[
$alias
];
}
}
elseif
(
$fk
instanceof
Doctrine_Relation_ForeignKey
||
$fk
instanceof
Doctrine_Relation_LocalKey
)
{
switch
(
$fk
->
getType
())
:
case
Doctrine_Relation
::
ONE_COMPOSITE
:
if
(
isset
(
$this
->
originals
[
$alias
])
&&
$this
->
originals
[
$alias
]
->
obtainIdentifier
()
!=
$this
->
references
[
$alias
]
->
obtainIdentifier
())
if
(
$fk
->
isOneToOne
())
{
if
(
isset
(
$this
->
originals
[
$alias
])
&&
$this
->
originals
[
$alias
]
->
obtainIdentifier
()
!=
$this
->
references
[
$alias
]
->
obtainIdentifier
())
$this
->
originals
[
$alias
]
->
delete
();
}
else
{
if
(
isset
(
$this
->
references
[
$alias
]))
{
$new
=
$this
->
references
[
$alias
];
break
;
case
Doctrine_Relation
::
MANY_COMPOSITE
:
if
(
isset
(
$this
->
references
[
$alias
]))
{
$new
=
$this
->
references
[
$alias
];
if
(
!
isset
(
$this
->
originals
[
$alias
]))
$record
->
loadReference
(
$alias
);
$operations
=
Doctrine_Relation
::
getDeleteOperations
(
$this
->
originals
[
$alias
],
$new
);
if
(
!
isset
(
$this
->
originals
[
$alias
]))
$record
->
loadReference
(
$alias
);
foreach
(
$operations
as
$r
)
{
$r
->
delete
();
}
$operations
=
Doctrine_Relation
::
getDeleteOperations
(
$this
->
originals
[
$alias
],
$new
);
$record
->
assignOriginals
(
$alias
,
clone
$this
->
references
[
$alias
]);
foreach
(
$operations
as
$r
)
{
$r
->
delete
();
}
break
;
endswitch
;
$record
->
assignOriginals
(
$alias
,
clone
$this
->
references
[
$alias
]);
}
}
}
endforeach
;
}
...
...
lib/Doctrine/Record.php
View file @
966450d4
...
...
@@ -994,7 +994,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return void
*/
final
public
function
saveAssociations
()
{
foreach
(
$this
->
table
->
getRelations
()
as
$fk
)
:
foreach
(
$this
->
table
->
getRelations
()
as
$fk
)
{
$table
=
$fk
->
getTable
();
$name
=
$table
->
getComponentName
();
$alias
=
$this
->
table
->
getAlias
(
$name
);
...
...
@@ -1035,13 +1035,11 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
elseif
(
$fk
instanceof
Doctrine_Relation_ForeignKey
||
$fk
instanceof
Doctrine_Relation_LocalKey
)
{
switch
(
$fk
->
getType
())
:
case
Doctrine_Relation
::
ONE_COMPOSITE
:
if
(
$fk
->
isOneToOne
())
{
if
(
isset
(
$this
->
originals
[
$alias
])
&&
$this
->
originals
[
$alias
]
->
obtainIdentifier
()
!=
$this
->
references
[
$alias
]
->
obtainIdentifier
())
$this
->
originals
[
$alias
]
->
delete
();
break
;
case
Doctrine_Relation
::
MANY_COMPOSITE
:
}
else
{
if
(
isset
(
$this
->
references
[
$alias
]))
{
$new
=
$this
->
references
[
$alias
];
...
...
@@ -1056,10 +1054,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this
->
originals
[
$alias
]
=
clone
$this
->
references
[
$alias
];
}
break
;
endswitch
;
}
}
endforeach
;
}
}
/**
* getOriginals
...
...
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