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
47daaa9c
Commit
47daaa9c
authored
Apr 03, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Algorithm for creating the tables in correct order
parent
b1a3eed4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
79 additions
and
21 deletions
+79
-21
Connection.php
lib/Doctrine/Connection.php
+55
-6
UnitOfWork.php
lib/Doctrine/Connection/UnitOfWork.php
+1
-1
Sqlite.php
lib/Doctrine/Export/Sqlite.php
+1
-1
Record.php
lib/Doctrine/Record.php
+9
-7
Table.php
lib/Doctrine/Table.php
+13
-6
No files found.
lib/Doctrine/Connection.php
View file @
47daaa9c
...
...
@@ -42,6 +42,10 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
* keys representing Doctrine_Table component names and values as Doctrine_Table objects
*/
protected
$tables
=
array
();
/**
* @var array $exported
*/
protected
$exported
=
array
();
/**
* @var string $driverName the name of this connection driver
*/
...
...
@@ -751,15 +755,59 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$class
=
$name
.
'Table'
;
if
(
class_exists
(
$class
)
&&
in_array
(
'Doctrine_Table'
,
class_parents
(
$class
)))
{
$table
=
new
$class
(
$name
,
$this
,
$allowExport
);
$table
=
new
$class
(
$name
,
$this
);
}
else
{
$table
=
new
Doctrine_Table
(
$name
,
$this
,
$allowExport
);
$table
=
new
Doctrine_Table
(
$name
,
$this
);
}
$this
->
tables
[
$name
]
=
$table
;
if
(
$table
->
getAttribute
(
Doctrine
::
ATTR_EXPORT
)
&
Doctrine
::
EXPORT_TABLES
)
{
$table
->
export
();
if
(
$allowExport
)
{
// the following is an algorithm for loading all
// the related tables for all loaded tables
$next
=
count
(
$this
->
tables
);
$prev
=
count
(
$this
->
exported
);
$stack
=
$this
->
exported
;
while
(
$prev
<
$next
)
{
$prev
=
count
(
$this
->
tables
);
foreach
(
$this
->
tables
as
$name
=>
$tableObject
)
{
if
(
isset
(
$stack
[
$name
]))
{
continue
;
}
else
{
$stack
[
$name
]
=
true
;
}
$tableObject
->
getRelations
();
//$this->getTable('RelationTestChild')->getRelation('Children');
}
$next
=
count
(
$this
->
tables
);
}
// when all the tables are loaded we build the array in which the order of the tables is
// relationally correct so that then those can be created in the given order)
$names
=
array_keys
(
$this
->
tables
);
$names
=
$this
->
unitOfWork
->
buildFlushTree
(
$names
);
foreach
(
$names
as
$name
)
{
$tableObject
=
$this
->
tables
[
$name
];
if
(
isset
(
$this
->
exported
[
$name
]))
{
continue
;
}
if
(
$tableObject
->
getAttribute
(
Doctrine
::
ATTR_EXPORT
)
&
Doctrine
::
EXPORT_TABLES
)
{
$tableObject
->
export
();
}
$this
->
exported
[
$name
]
=
true
;
}
}
return
$table
;
...
...
@@ -863,6 +911,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
public
function
evictTables
()
{
$this
->
tables
=
array
();
$this
->
exported
=
array
();
}
/**
* close
...
...
lib/Doctrine/Connection/UnitOfWork.php
View file @
47daaa9c
...
...
@@ -49,7 +49,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module implemen
foreach
(
$tables
as
$k
=>
$table
)
{
if
(
!
(
$table
instanceof
Doctrine_Table
))
{
$table
=
$this
->
conn
->
getTable
(
$table
);
$table
=
$this
->
conn
->
getTable
(
$table
,
false
);
}
$nm
=
$table
->
getComponentName
();
...
...
lib/Doctrine/Export/Sqlite.php
View file @
47daaa9c
...
...
@@ -190,7 +190,7 @@ class Doctrine_Export_Sqlite extends Doctrine_Export
foreach
(
$fk
as
$definition
)
{
$query
=
'CREATE TRIGGER doctrine_'
.
$name
.
'_cscd_delete '
.
'AFTER DELETE ON '
.
$name
.
' FOR EACH
STATEMENT
'
.
'AFTER DELETE ON '
.
$name
.
' FOR EACH
ROW
'
.
'BEGIN '
.
'DELETE FROM '
.
$definition
[
'foreignTable'
]
.
' WHERE '
;
...
...
lib/Doctrine/Record.php
View file @
47daaa9c
...
...
@@ -148,7 +148,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
else
{
$class
=
get_class
(
$this
);
// get the table of this class
$this
->
_table
=
Doctrine_Manager
::
getInstance
()
->
getConnectionForComponent
(
$class
)
->
getTable
(
get_class
(
$this
));
$this
->
_table
=
Doctrine_Manager
::
getInstance
()
->
getTable
(
get_class
(
$this
));
$exists
=
false
;
}
...
...
lib/Doctrine/Table.php
View file @
47daaa9c
...
...
@@ -172,7 +172,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
* @throws Doctrine_Table_Exception if there is already an instance of this table
* @return void
*/
public
function
__construct
(
$name
,
Doctrine_Connection
$conn
,
$allowExport
)
public
function
__construct
(
$name
,
Doctrine_Connection
$conn
)
{
$this
->
conn
=
$conn
;
...
...
@@ -684,7 +684,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
public
function
getBound
(
$name
)
{
if
(
!
isset
(
$this
->
bound
[
$name
]))
{
throw
new
Doctrine_Table_Exception
(
'Unknown bound '
.
$name
);
throw
new
Doctrine_Table_Exception
(
'Unknown bound '
.
$name
);
}
return
$this
->
bound
[
$name
];
}
...
...
@@ -737,7 +737,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
* @return void
*/
public
function
unbindAll
()
{
{
throw
new
Exception
();
$this
->
bound
=
array
();
$this
->
relations
=
array
();
$this
->
boundAliases
=
array
();
...
...
@@ -850,6 +850,13 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
if
(
isset
(
$this
->
relations
[
$name
]))
{
return
$this
->
relations
[
$name
];
}
if
(
!
$this
->
conn
->
hasTable
(
$this
->
options
[
'name'
]))
{
$allowExport
=
true
;
}
else
{
$allowExport
=
false
;
}
if
(
isset
(
$this
->
bound
[
$name
]))
{
$definition
=
$this
->
bound
[
$name
];
...
...
@@ -857,7 +864,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
list
(
$component
,
$definition
[
'foreign'
])
=
explode
(
'.'
,
$definition
[
'field'
]);
unset
(
$definition
[
'field'
]);
$definition
[
'table'
]
=
$this
->
conn
->
getTable
(
$definition
[
'class'
],
false
);
$definition
[
'table'
]
=
$this
->
conn
->
getTable
(
$definition
[
'class'
],
$allowExport
);
$definition
[
'constraint'
]
=
false
;
if
(
$component
==
$this
->
options
[
'name'
]
||
in_array
(
$component
,
$this
->
options
[
'parents'
]))
{
...
...
@@ -930,7 +937,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
if
(
$e2
[
0
]
!=
$component
)
{
throw
new
Doctrine_Table_Exception
(
$e2
[
0
]
.
' doesn\'t match '
.
$component
);
}
$associationTable
=
$this
->
conn
->
getTable
(
$e2
[
0
]);
$associationTable
=
$this
->
conn
->
getTable
(
$e2
[
0
]
,
$allowExport
);
if
(
count
(
$fields
)
>
1
)
{
// SELF-REFERENCING THROUGH JOIN TABLE
...
...
@@ -985,6 +992,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
return
$this
->
relations
[
$name
];
}
// load all relations
$this
->
getRelations
();
...
...
@@ -1002,7 +1010,6 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable
*/
final
public
function
getRelations
()
{
$a
=
array
();
foreach
(
$this
->
bound
as
$k
=>
$v
)
{
$this
->
getRelation
(
$k
);
}
...
...
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