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
71338c3d
Commit
71338c3d
authored
May 22, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
drafting the new relation model, still a lot of work
parent
b3b1f617
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
153 additions
and
426 deletions
+153
-426
UnitOfWork.php
lib/Doctrine/Connection/UnitOfWork.php
+6
-5
Statement.php
lib/Doctrine/Db/Statement.php
+6
-2
Query.php
lib/Doctrine/Query.php
+8
-6
Record.php
lib/Doctrine/Record.php
+38
-25
Relation.php
lib/Doctrine/Relation.php
+2
-2
Association.php
lib/Doctrine/Relation/Association.php
+3
-3
Self.php
lib/Doctrine/Relation/Association/Self.php
+5
-5
ForeignKey.php
lib/Doctrine/Relation/ForeignKey.php
+3
-3
Parser.php
lib/Doctrine/Relation/Parser.php
+22
-9
Table.php
lib/Doctrine/Table.php
+60
-366
No files found.
lib/Doctrine/Connection/UnitOfWork.php
View file @
71338c3d
...
...
@@ -79,7 +79,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
// skip self-referenced relations
if
(
$name
===
$nm
)
{
continue
;
}
}
if
(
$rel
instanceof
Doctrine_Relation_ForeignKey
)
{
if
(
$index2
!==
false
)
{
...
...
@@ -257,10 +257,11 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
}
}
/**
* update
* updates the given record
*
* @param Doctrine_Record $record
* @return boolean
* @param Doctrine_Record $record
record to be updated
* @return boolean
whether or not the update was successful
*/
public
function
update
(
Doctrine_Record
$record
)
{
...
...
@@ -301,7 +302,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
.
' WHERE '
.
implode
(
' = ? AND '
,
$record
->
getTable
()
->
getPrimaryKeys
())
.
' = ?'
;
$stmt
=
$this
->
conn
->
getD
BH
()
->
prepare
(
$sql
);
$stmt
=
$this
->
conn
->
getD
bh
()
->
prepare
(
$sql
);
$stmt
->
execute
(
$params
);
$record
->
assignIdentifier
(
true
);
...
...
@@ -335,7 +336,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$id
=
$this
->
conn
->
sequence
->
nextId
(
$seq
);
$name
=
$record
->
getTable
()
->
getIdentifier
();
$array
[
$name
]
=
$id
;
$record
->
assignIdentifier
(
$id
);
}
...
...
lib/Doctrine/Db/Statement.php
View file @
71338c3d
...
...
@@ -44,7 +44,7 @@ class Doctrine_Db_Statement implements Doctrine_Adapter_Statement_Interface
$this
->
stmt
=
$stmt
;
if
(
$stmt
===
false
)
{
throw
new
Doctrine_Db_Exception
(
'Unknown statement object given.'
);
throw
new
Doctrine_Db_Exception
(
'Unknown statement object given.'
);
}
}
/**
...
...
@@ -205,7 +205,11 @@ class Doctrine_Db_Statement implements Doctrine_Adapter_Statement_Interface
$skip
=
$this
->
adapter
->
getListener
()
->
onPreExecute
(
$event
);
if
(
!
$skip
)
{
$this
->
stmt
->
execute
(
$params
);
if
(
isset
(
$params
[
0
])
&&
is_array
(
$params
[
0
]))
{
print_r
(
$params
);
throw
new
Exception
();
}
$this
->
stmt
->
execute
((
array
)
$params
);
$this
->
adapter
->
incrementQueryCount
();
}
...
...
lib/Doctrine/Query.php
View file @
71338c3d
...
...
@@ -66,6 +66,13 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
* @var array $_enumParams an array containing the keys of the parameters that should be enumerated
*/
protected
$_enumParams
=
array
();
/**
* @var array $_options an array of options
*/
protected
$_options
=
array
(
'fetchMode'
=>
Doctrine
::
FETCH_RECORD
,
'cacheMode'
=>
null
,
);
/**
* @var array $_dqlParts an array containing all DQL query parts
*/
...
...
@@ -483,7 +490,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$q
=
'UPDATE '
;
break
;
case
self
::
SELECT
:
$distinct
=
(
$this
->
isDistinct
()
)
?
'DISTINCT '
:
''
;
$distinct
=
(
$this
->
parts
[
'distinct'
]
)
?
'DISTINCT '
:
''
;
$q
=
'SELECT '
.
$distinct
.
implode
(
', '
,
$this
->
parts
[
'select'
])
.
' FROM '
;
break
;
...
...
@@ -565,11 +572,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
// build the basic query
$str
=
''
;
if
(
$this
->
isDistinct
())
{
$str
=
'DISTINCT '
;
}
$q
=
$this
->
getQueryBase
();
$q
.=
$this
->
buildFromPart
();
...
...
lib/Doctrine/Record.php
View file @
71338c3d
...
...
@@ -901,8 +901,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
foreach
(
$saveLater
as
$fk
)
{
$table
=
$fk
->
getTable
();
$alias
=
$this
->
_table
->
getAlias
(
$table
->
getComponentName
());
$alias
=
$fk
->
getAlias
();
if
(
isset
(
$this
->
_references
[
$alias
]))
{
$obj
=
$this
->
_references
[
$alias
];
...
...
@@ -1011,8 +1010,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$a
[
$v
]
=
$this
->
_table
->
enumIndex
(
$v
,
$this
->
_data
[
$v
]);
break
;
default
:
if
(
$this
->
_data
[
$v
]
instanceof
Doctrine_Record
)
if
(
$this
->
_data
[
$v
]
instanceof
Doctrine_Record
)
{
$this
->
_data
[
$v
]
=
$this
->
_data
[
$v
]
->
getIncremented
();
}
$a
[
$v
]
=
$this
->
_data
[
$v
];
}
...
...
@@ -1273,48 +1273,61 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
}
/**
* ownsOne
* binds One-to-One composite relation
*
* @param string $objTableName
* @param string $fkField
* @return void
* @param string $componentName the name of the related component
* @param string $options relation options
* @see Doctrine_Relation::_$definition
* @return Doctrine_Record this object
*/
final
public
function
ownsOne
(
$componentName
,
$foreignKey
,
$options
=
null
)
public
function
ownsOne
(
)
{
$this
->
_table
->
bind
(
$componentName
,
$foreignKey
,
Doctrine_Relation
::
ONE_COMPOSITE
,
$options
);
$this
->
_table
->
bind
(
func_get_args
(),
Doctrine_Relation
::
ONE_COMPOSITE
);
return
$this
;
}
/**
* binds One-to-Many composite relation
* ownsMany
* binds One-to-Many / Many-to-Many composite relation
*
* @param string $objTableName
* @param string $fkField
* @return void
* @param string $componentName the name of the related component
* @param string $options relation options
* @see Doctrine_Relation::_$definition
* @return Doctrine_Record this object
*/
final
public
function
ownsMany
(
$componentName
,
$foreignKey
,
$options
=
null
)
public
function
ownsMany
(
)
{
$this
->
_table
->
bind
(
$componentName
,
$foreignKey
,
Doctrine_Relation
::
MANY_COMPOSITE
,
$options
);
$this
->
_table
->
bind
(
func_get_args
(),
Doctrine_Relation
::
MANY_COMPOSITE
);
return
$this
;
}
/**
* hasOne
* binds One-to-One aggregate relation
*
* @param string $objTableName
* @param string $fkField
* @return void
* @param string $componentName the name of the related component
* @param string $options relation options
* @see Doctrine_Relation::_$definition
* @return Doctrine_Record this object
*/
final
public
function
hasOne
(
$componentName
,
$foreignKey
,
$options
=
null
)
public
function
hasOne
(
)
{
$this
->
_table
->
bind
(
$componentName
,
$foreignKey
,
Doctrine_Relation
::
ONE_AGGREGATE
,
$options
);
$this
->
_table
->
bind
(
func_get_args
(),
Doctrine_Relation
::
ONE_AGGREGATE
);
return
$this
;
}
/**
* binds One-to-Many aggregate relation
* hasMany
* binds One-to-Many / Many-to-Many aggregate relation
*
* @param string $objTableName
* @param string $fkField
* @return void
* @param string $componentName the name of the related component
* @param string $options relation options
* @see Doctrine_Relation::_$definition
* @return Doctrine_Record this object
*/
final
public
function
hasMany
(
$componentName
,
$foreignKey
,
$options
=
null
)
public
function
hasMany
(
)
{
$this
->
_table
->
bind
(
$componentName
,
$foreignKey
,
Doctrine_Relation
::
MANY_AGGREGATE
,
$options
);
$this
->
_table
->
bind
(
func_get_args
(),
Doctrine_Relation
::
MANY_AGGREGATE
);
return
$this
;
}
/**
* hasColumn
...
...
lib/Doctrine/Relation.php
View file @
71338c3d
...
...
@@ -62,7 +62,7 @@ abstract class Doctrine_Relation
'class'
=>
true
,
'type'
=>
true
,
'name'
=>
false
,
'
assocTable'
=>
false
,
'
refTable'
=>
false
,
'onDelete'
=>
false
,
'onUpdate'
=>
false
,
'deferred'
=>
false
,
...
...
@@ -80,7 +80,7 @@ abstract class Doctrine_Relation
*
* table the foreign table object
*
*
assocTable the association
table object (if any)
*
refTable the reference
table object (if any)
*
* onDelete referential delete action
*
...
...
lib/Doctrine/Relation/Association.php
View file @
71338c3d
...
...
@@ -40,11 +40,11 @@ class Doctrine_Relation_Association extends Doctrine_Relation
*/
public
function
getAssociationFactory
()
{
return
$this
->
definition
[
'
assoc
Table'
];
return
$this
->
definition
[
'
ref
Table'
];
}
public
function
getAssociationTable
()
{
return
$this
->
definition
[
'
assoc
Table'
];
return
$this
->
definition
[
'
ref
Table'
];
}
/**
* getRelationDql
...
...
@@ -54,7 +54,7 @@ class Doctrine_Relation_Association extends Doctrine_Relation
*/
public
function
getRelationDql
(
$count
,
$context
=
'record'
)
{
$component
=
$this
->
definition
[
'
assoc
Table'
]
->
getComponentName
();
$component
=
$this
->
definition
[
'
ref
Table'
]
->
getComponentName
();
switch
(
$context
)
{
case
"record"
:
$sub
=
'SQL:SELECT '
.
$this
->
definition
[
'foreign'
]
.
...
...
lib/Doctrine/Relation/Association/Self.php
View file @
71338c3d
...
...
@@ -43,17 +43,17 @@ class Doctrine_Relation_Association_Self extends Doctrine_Relation_Association
switch
(
$context
)
{
case
'record'
:
$sub
=
'SELECT '
.
$this
->
definition
[
'foreign'
]
.
' FROM '
.
$this
->
definition
[
'
assoc
Table'
]
->
getTableName
()
.
' FROM '
.
$this
->
definition
[
'
ref
Table'
]
->
getTableName
()
.
' WHERE '
.
$this
->
definition
[
'local'
]
.
' = ?'
;
$sub2
=
'SELECT '
.
$this
->
definition
[
'local'
]
.
' FROM '
.
$this
->
definition
[
'
assoc
Table'
]
->
getTableName
()
.
' FROM '
.
$this
->
definition
[
'
ref
Table'
]
->
getTableName
()
.
' WHERE '
.
$this
->
definition
[
'foreign'
]
.
' = ?'
;
$dql
=
'FROM '
.
$this
->
definition
[
'table'
]
->
getComponentName
()
.
'.'
.
$this
->
definition
[
'
assoc
Table'
]
->
getComponentName
()
.
'.'
.
$this
->
definition
[
'
ref
Table'
]
->
getComponentName
()
.
' WHERE '
.
$this
->
definition
[
'table'
]
->
getComponentName
()
.
'.'
.
$this
->
definition
[
'table'
]
->
getIdentifier
()
.
' IN ('
.
$sub
.
')'
...
...
@@ -63,9 +63,9 @@ class Doctrine_Relation_Association_Self extends Doctrine_Relation_Association
break
;
case
'collection'
:
$sub
=
substr
(
str_repeat
(
'?, '
,
$count
),
0
,
-
2
);
$dql
=
'FROM '
.
$this
->
definition
[
'
assocTable'
]
->
getComponentName
()
$dql
=
'FROM '
.
$this
->
definition
[
'
refTable'
]
->
getComponentName
()
.
'.'
.
$this
->
definition
[
'table'
]
->
getComponentName
()
.
' WHERE '
.
$this
->
definition
[
'
assocTable'
]
->
getComponentName
()
.
' WHERE '
.
$this
->
definition
[
'
refTable'
]
->
getComponentName
()
.
'.'
.
$this
->
definition
[
'local'
]
.
' IN ('
.
$sub
.
')'
;
};
...
...
lib/Doctrine/Relation/ForeignKey.php
View file @
71338c3d
...
...
@@ -45,7 +45,7 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation
{
$id
=
array
();
foreach
((
array
)
$this
->
definition
[
'local'
]
as
$local
)
{
$id
=
$record
->
get
(
$local
);
$id
[]
=
$record
->
get
(
$local
);
}
if
(
$this
->
isOneToOne
())
{
if
(
empty
(
$id
))
{
...
...
@@ -54,7 +54,7 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation
$dql
=
'FROM '
.
$this
->
getTable
()
->
getComponentName
()
.
' WHERE '
.
$this
->
getCondition
();
$coll
=
$this
->
getTable
()
->
getConnection
()
->
query
(
$dql
,
array
(
$id
)
);
$coll
=
$this
->
getTable
()
->
getConnection
()
->
query
(
$dql
,
$id
);
$related
=
$coll
[
0
];
}
...
...
@@ -66,7 +66,7 @@ class Doctrine_Relation_ForeignKey extends Doctrine_Relation
$related
=
new
Doctrine_Collection
(
$this
->
getTable
());
}
else
{
$query
=
$this
->
getRelationDql
(
1
);
$related
=
$this
->
getTable
()
->
getConnection
()
->
query
(
$query
,
array
(
$id
)
);
$related
=
$this
->
getTable
()
->
getConnection
()
->
query
(
$query
,
$id
);
}
$related
->
setReference
(
$record
,
$this
);
}
...
...
lib/Doctrine/Relation/Parser.php
View file @
71338c3d
...
...
@@ -126,6 +126,8 @@ class Doctrine_Relation_Parser
if
(
isset
(
$this
->
_pending
[
$alias
]))
{
$def
=
$this
->
_pending
[
$alias
];
// check if reference class name exists
// if it does we are dealing with association relation
if
(
isset
(
$def
[
'refClass'
]))
{
$def
=
$this
->
completeAssocDefinition
(
$def
);
$localClasses
=
array_merge
(
$this
->
_table
->
getOption
(
'parents'
),
array
(
$this
->
_table
->
getComponentName
()));
...
...
@@ -134,7 +136,10 @@ class Doctrine_Relation_Parser
!
isset
(
$this
->
_relations
[
$def
[
'refClass'
]]))
{
$def
[
'refTable'
]
->
getRelationParser
()
->
bind
(
$this
->
_table
->
getComponentName
(),
array
(
'type'
=>
Doctrine_Relation
::
ONE
));
array
(
'type'
=>
Doctrine_Relation
::
ONE
,
'local'
=>
$def
[
'local'
],
'foreign'
=>
$this
->
_table
->
getIdentifier
(),
));
$this
->
bind
(
$def
[
'refClass'
],
array
(
'type'
=>
Doctrine_Relation
::
MANY
,
'foreign'
=>
$def
[
'local'
]));
...
...
@@ -145,15 +150,20 @@ class Doctrine_Relation_Parser
$rel
=
new
Doctrine_Relation_Association
(
$def
);
}
}
else
{
// simple foreign key relation
$def
=
$this
->
completeDefinition
(
$def
);
if
(
!
isset
(
$def
[
'foreign'
]))
{
Doctrine
::
dump
(
$def
);
}
$rel
=
new
Doctrine_Relation_ForeignKey
(
$def
);
if
(
isset
(
$def
[
'localKey'
]))
{
$rel
=
new
Doctrine_Relation_LocalKey
(
$def
);
}
else
{
$rel
=
new
Doctrine_Relation_ForeignKey
(
$def
);
}
}
if
(
isset
(
$rel
))
{
unset
(
$this
->
_pending
[
$name
]);
// unset pending relation
unset
(
$this
->
_pending
[
$alias
]);
$this
->
_relations
[
$alias
]
=
$rel
;
return
$rel
;
}
}
...
...
@@ -288,6 +298,7 @@ class Doctrine_Relation_Parser
// the foreign field is likely to be the
// identifier of the foreign class
$def
[
'foreign'
]
=
$def
[
'table'
]
->
getIdentifier
();
$def
[
'localKey'
]
=
true
;
}
}
}
else
{
...
...
@@ -295,6 +306,7 @@ class Doctrine_Relation_Parser
// local key not set, but foreign key is set
// try to guess the local key
if
(
$def
[
'foreign'
]
===
$def
[
'table'
]
->
getIdentifier
())
{
$def
[
'localKey'
]
=
true
;
$def
[
'local'
]
=
$this
->
guessColumns
(
$foreignClasses
,
$this
->
_table
);
}
else
{
$def
[
'local'
]
=
$this
->
_table
->
getIdentifier
();
...
...
@@ -316,6 +328,7 @@ class Doctrine_Relation_Parser
if
(
$table2
->
hasColumn
(
$column
))
{
$def
[
'foreign'
]
=
$column
;
$def
[
'local'
]
=
$table
->
getIdentifier
();
$def
[
'localKey'
]
=
true
;
return
$def
;
}
}
...
...
@@ -334,8 +347,8 @@ class Doctrine_Relation_Parser
return
$def
;
}
}
}
Doctrine
::
dump
(
$this
->
_table
->
getComponentName
());
Doctrine
::
dump
(
$def
);
}
Doctrine
::
dump
(
$def
);
throw
new
Doctrine_Relation_Parser_Exception
(
"Couldn't complete relation definition."
);
}
}
...
...
lib/Doctrine/Table.php
View file @
71338c3d
This diff is collapsed.
Click to expand it.
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