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
ed62d636
Commit
ed62d636
authored
Sep 28, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved relation classes under Doctrine_Relation namespace, fixes #134
Ticket: 134
parent
c8c1397f
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
400 additions
and
61 deletions
+400
-61
Association.php
lib/Doctrine/Association.php
+2
-2
Collection.php
lib/Doctrine/Collection.php
+9
-9
Compiler.php
lib/Doctrine/Compiler.php
+5
-6
Exception.php
lib/Doctrine/Compiler/Exception.php
+29
-0
Connection.php
lib/Doctrine/Connection.php
+6
-6
UnitOfWork.php
lib/Doctrine/Connection/UnitOfWork.php
+4
-4
ForeignKey.php
lib/Doctrine/ForeignKey.php
+3
-3
Hydrate.php
lib/Doctrine/Hydrate.php
+1
-1
LocalKey.php
lib/Doctrine/LocalKey.php
+2
-2
Manager.php
lib/Doctrine/Manager.php
+10
-1
Query.php
lib/Doctrine/Query.php
+3
-3
Record.php
lib/Doctrine/Record.php
+7
-11
Association.php
lib/Doctrine/Relation/Association.php
+99
-0
Self.php
lib/Doctrine/Relation/Association/Self.php
+90
-0
ForeignKey.php
lib/Doctrine/Relation/ForeignKey.php
+64
-0
LocalKey.php
lib/Doctrine/Relation/LocalKey.php
+53
-0
Session.php
lib/Doctrine/Session.php
+7
-7
Table.php
lib/Doctrine/Table.php
+6
-6
No files found.
lib/Doctrine/Association.php
View file @
ed62d636
...
...
@@ -19,7 +19,7 @@
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Association this class takes care of association mapping
* Doctrine_
Relation_
Association this class takes care of association mapping
* (= many-to-many relationships, where the relationship is handled with an additional relational table
* which holds 2 foreign keys)
*
...
...
@@ -28,7 +28,7 @@
* @url www.phpdoctrine.com
* @license LGPL
*/
class
Doctrine_Association
extends
Doctrine_Relation
{
class
Doctrine_
Relation_
Association
extends
Doctrine_Relation
{
/**
* @var Doctrine_Table $associationTable
*/
...
...
lib/Doctrine/Collection.php
View file @
ed62d636
...
...
@@ -243,8 +243,8 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this
->
reference
=
$record
;
$this
->
relation
=
$relation
;
if
(
$relation
instanceof
Doctrine_ForeignKey
||
$relation
instanceof
Doctrine_LocalKey
)
{
if
(
$relation
instanceof
Doctrine_
Relation_
ForeignKey
||
$relation
instanceof
Doctrine_
Relation_
LocalKey
)
{
$this
->
reference_field
=
$relation
->
getForeign
();
...
...
@@ -257,7 +257,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$record
->
set
(
$this
->
reference_field
,
$this
->
reference
,
false
);
}
}
}
elseif
(
$relation
instanceof
Doctrine_Association
)
{
}
elseif
(
$relation
instanceof
Doctrine_
Relation_
Association
)
{
}
}
...
...
@@ -315,7 +315,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
endswitch
;
if
(
isset
(
$this
->
relation
))
{
if
(
$this
->
relation
instanceof
Doctrine_ForeignKey
)
{
if
(
$this
->
relation
instanceof
Doctrine_
Relation_
ForeignKey
)
{
$params
[]
=
$this
->
reference
->
getIncremented
();
$where
[]
=
$this
->
reference_field
.
" = ?"
;
...
...
@@ -331,7 +331,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
}
}
elseif
(
$this
->
relation
instanceof
Doctrine_Association
)
{
}
elseif
(
$this
->
relation
instanceof
Doctrine_
Relation_
Association
)
{
$asf
=
$this
->
relation
->
getAssociationFactory
();
$query
=
'SELECT '
.
$foreign
.
" FROM "
.
$asf
->
getTableName
()
.
" WHERE "
.
$local
.
"="
.
$this
->
getIncremented
();
...
...
@@ -582,7 +582,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$local
=
$rel
->
getLocal
();
$list
=
array
();
if
(
$rel
instanceof
Doctrine_
LocalKey
||
$rel
instanceof
Doctrine
_ForeignKey
)
{
if
(
$rel
instanceof
Doctrine_
Relation_LocalKey
||
$rel
instanceof
Doctrine_Relation
_ForeignKey
)
{
foreach
(
$this
->
data
as
$record
)
:
$list
[]
=
$record
[
$local
];
endforeach
;
...
...
@@ -613,7 +613,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$foreign
=
$rel
->
getForeign
();
$local
=
$rel
->
getLocal
();
if
(
$rel
instanceof
Doctrine_LocalKey
)
{
if
(
$rel
instanceof
Doctrine_
Relation_
LocalKey
)
{
foreach
(
$this
->
data
as
$key
=>
$record
)
{
foreach
(
$coll
as
$k
=>
$related
)
{
if
(
$related
[
$foreign
]
==
$record
[
$local
])
{
...
...
@@ -621,7 +621,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
}
}
}
}
elseif
(
$rel
instanceof
Doctrine_ForeignKey
)
{
}
elseif
(
$rel
instanceof
Doctrine_
Relation_
ForeignKey
)
{
foreach
(
$this
->
data
as
$key
=>
$record
)
{
if
(
$record
->
getState
()
==
Doctrine_Record
::
STATE_TCLEAN
||
$record
->
getState
()
==
Doctrine_Record
::
STATE_TDIRTY
)
...
...
@@ -638,7 +638,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$this
->
data
[
$key
]
->
setRelated
(
$name
,
$sub
);
}
}
elseif
(
$rel
instanceof
Doctrine_Association
)
{
}
elseif
(
$rel
instanceof
Doctrine_
Relation_
Association
)
{
$identifier
=
$this
->
table
->
getIdentifier
();
$asf
=
$rel
->
getAssociationFactory
();
$name
=
$table
->
getComponentName
();
...
...
lib/Doctrine/Compiler.php
View file @
ed62d636
...
...
@@ -20,8 +20,8 @@
*/
/**
* Doctrine
*
the base class of Doctrine framework
* Doctrine
_Compiler
*
This class can be used for compiling the entire Doctrine framework into a single file
*
* @package Doctrine
* @author Konsta Vesterinen
...
...
@@ -104,7 +104,7 @@ class Doctrine_Compiler {
echo
"Adding
$file
"
.
PHP_EOL
;
if
(
!
file_exists
(
$file
))
throw
new
Doctrine_Exception
(
"Couldn't compile
$file
. File
$file
does not exists."
);
throw
new
Doctrine_
Compiler_
Exception
(
"Couldn't compile
$file
. File
$file
does not exists."
);
Doctrine
::
autoload
(
$class
);
$refl
=
new
ReflectionClass
(
$class
);
...
...
@@ -129,11 +129,10 @@ class Doctrine_Compiler {
$fp
=
@
fopen
(
$target
,
'w'
);
if
(
$fp
===
false
)
throw
new
Doctrine_Exception
(
"Couldn't write compiled data. Failed to open
$target
"
);
throw
new
Doctrine_
Compiler_
Exception
(
"Couldn't write compiled data. Failed to open
$target
"
);
fwrite
(
$fp
,
"<?php"
.
" class InvalidKeyException extends Exception { }"
.
" class DQLException extends Exception { }"
.
implode
(
''
,
$ret
)
);
fclose
(
$fp
);
...
...
@@ -141,7 +140,7 @@ class Doctrine_Compiler {
$stripped
=
php_strip_whitespace
(
$target
);
$fp
=
@
fopen
(
$target
,
'w'
);
if
(
$fp
===
false
)
throw
new
Doctrine_Exception
(
"Couldn't write compiled data. Failed to open
$file
"
);
throw
new
Doctrine_
Compiler_
Exception
(
"Couldn't write compiled data. Failed to open
$file
"
);
fwrite
(
$fp
,
$stripped
);
fclose
(
$fp
);
}
...
...
lib/Doctrine/Compiler/Exception.php
0 → 100644
View file @
ed62d636
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Compiler_Exception
*
* @package Doctrine
* @author Konsta Vesterinen
* @license LGPL
*/
class
Doctrine_Compiler_Exception
extends
Doctrine_Exception
{
}
lib/Doctrine/Connection.php
View file @
ed62d636
...
...
@@ -459,8 +459,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$saveLater
=
array
();
foreach
(
$record
->
getReferences
()
as
$k
=>
$v
)
{
$fk
=
$record
->
getTable
()
->
getRelation
(
$k
);
if
(
$fk
instanceof
Doctrine_ForeignKey
||
$fk
instanceof
Doctrine_LocalKey
)
{
if
(
$fk
instanceof
Doctrine_
Relation_
ForeignKey
||
$fk
instanceof
Doctrine_
Relation_
LocalKey
)
{
switch
(
$fk
->
getType
())
:
case
Doctrine_Relation
::
ONE_COMPOSITE
:
case
Doctrine_Relation
::
MANY_COMPOSITE
:
...
...
@@ -482,7 +482,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
break
;
endswitch
;
}
elseif
(
$fk
instanceof
Doctrine_Association
)
{
}
elseif
(
$fk
instanceof
Doctrine_
Relation_
Association
)
{
$v
->
save
();
}
}
...
...
@@ -517,7 +517,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
$name
=
$table
->
getComponentName
();
$alias
=
$this
->
table
->
getAlias
(
$name
);
if
(
$rel
instanceof
Doctrine_Association
)
{
if
(
$rel
instanceof
Doctrine_
Relation_
Association
)
{
switch
(
$rel
->
getType
())
:
case
Doctrine_Relation
::
MANY_COMPOSITE
:
break
;
...
...
@@ -552,8 +552,8 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
}
break
;
endswitch
;
}
elseif
(
$fk
instanceof
Doctrine_ForeignKey
||
$fk
instanceof
Doctrine_LocalKey
)
{
}
elseif
(
$fk
instanceof
Doctrine_
Relation_
ForeignKey
||
$fk
instanceof
Doctrine_
Relation_
LocalKey
)
{
switch
(
$fk
->
getType
())
:
case
Doctrine_Relation
::
ONE_COMPOSITE
:
...
...
lib/Doctrine/Connection/UnitOfWork.php
View file @
ed62d636
...
...
@@ -68,7 +68,7 @@ class Doctrine_Connection_UnitOfWork implements IteratorAggregate, Countable {
// group relations
foreach
(
$rels
as
$key
=>
$rel
)
{
if
(
$rel
instanceof
Doctrine_ForeignKey
)
{
if
(
$rel
instanceof
Doctrine_
Relation_
ForeignKey
)
{
unset
(
$rels
[
$key
]);
array_unshift
(
$rels
,
$rel
);
}
...
...
@@ -83,7 +83,7 @@ class Doctrine_Connection_UnitOfWork implements IteratorAggregate, Countable {
if
(
$name
===
$nm
)
continue
;
if
(
$rel
instanceof
Doctrine_ForeignKey
)
{
if
(
$rel
instanceof
Doctrine_
Relation_
ForeignKey
)
{
if
(
$index2
!==
false
)
{
if
(
$index2
>=
$index
)
continue
;
...
...
@@ -95,7 +95,7 @@ class Doctrine_Connection_UnitOfWork implements IteratorAggregate, Countable {
$tree
[]
=
$name
;
}
}
elseif
(
$rel
instanceof
Doctrine_LocalKey
)
{
}
elseif
(
$rel
instanceof
Doctrine_
Relation_
LocalKey
)
{
if
(
$index2
!==
false
)
{
if
(
$index2
<=
$index
)
continue
;
...
...
@@ -106,7 +106,7 @@ class Doctrine_Connection_UnitOfWork implements IteratorAggregate, Countable {
array_unshift
(
$tree
,
$name
);
$index
++
;
}
}
elseif
(
$rel
instanceof
Doctrine_Association
)
{
}
elseif
(
$rel
instanceof
Doctrine_
Relation_
Association
)
{
$t
=
$rel
->
getAssociationFactory
();
$n
=
$t
->
getComponentName
();
...
...
lib/Doctrine/ForeignKey.php
View file @
ed62d636
...
...
@@ -20,14 +20,14 @@
*/
Doctrine
::
autoload
(
'Doctrine_Relation'
);
/**
* Doctrine_ForeignKey
* Doctrine_
Relation_
ForeignKey
* This class represents a foreign key relation
*
* @author Konsta Vesterinen
* @license LGPL
* @package Doctrine
*/
class
Doctrine_
ForeignKey
extends
Doctrine_Relation
{
class
Doctrine_
Relation_ForeignKey
extends
Doctrine_Relation
{
/**
* fetchRelatedFor
*
...
...
@@ -35,7 +35,7 @@ class Doctrine_ForeignKey extends Doctrine_Relation {
*
* @param Doctrine_Record $record
* @return Doctrine_Record|Doctrine_Collection
*/
*/
public
function
fetchRelatedFor
(
Doctrine_Record
$record
)
{
$id
=
$record
->
get
(
$this
->
local
);
...
...
lib/Doctrine/Hydrate.php
View file @
ed62d636
...
...
@@ -391,7 +391,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
if
(
$fk
->
isOneToOne
())
{
// one-to-one relation
if
(
$fk
instanceof
Doctrine_LocalKey
)
if
(
$fk
instanceof
Doctrine_
Relation_
LocalKey
)
$last
->
set
(
$fk
->
getLocal
(),
$record
->
getIncremented
(),
false
);
$last
->
set
(
$fk
->
getAlias
(),
$record
);
...
...
lib/Doctrine/LocalKey.php
View file @
ed62d636
...
...
@@ -20,14 +20,14 @@
*/
Doctrine
::
autoload
(
'Doctrine_Relation'
);
/**
* Doctrine_LocalKey
* Doctrine_
Relation_
LocalKey
* This class represents a local key relation
*
* @author Konsta Vesterinen
* @license LGPL
* @package Doctrine
*/
class
Doctrine_
LocalKey
extends
Doctrine_Relation
{
class
Doctrine_
Relation_LocalKey
extends
Doctrine_Relation
{
/**
* fetchRelatedFor
*
...
...
lib/Doctrine/Manager.php
View file @
ed62d636
...
...
@@ -115,13 +115,22 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
*
* @return Doctrine_Manager
*/
final
public
static
function
getInstance
()
{
public
static
function
getInstance
()
{
static
$instance
;
if
(
!
isset
(
$instance
))
$instance
=
new
self
();
return
$instance
;
}
/**
* connection
* a short cut for Doctrine_Manager::getInstance()->openConnection($dbh);
*
* @return Doctrine_Connection
*/
public
static
function
connection
(
PDO
$dbh
)
{
return
Doctrine_Manager
::
getInstance
()
->
openConnection
(
$dbh
);
}
/**
* install
*
...
...
lib/Doctrine/Query.php
View file @
ed62d636
...
...
@@ -732,12 +732,12 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
$this
->
needsSubquery
=
true
;
}
if
(
$fk
instanceof
Doctrine_ForeignKey
||
$fk
instanceof
Doctrine_LocalKey
)
{
if
(
$fk
instanceof
Doctrine_
Relation_
ForeignKey
||
$fk
instanceof
Doctrine_
Relation_
LocalKey
)
{
$this
->
parts
[
"join"
][
$tname
][
$tname2
]
=
$join
.
$aliasString
.
" ON "
.
$tname
.
"."
.
$fk
->
getLocal
()
.
" = "
.
$tname2
.
"."
.
$fk
->
getForeign
();
}
elseif
(
$fk
instanceof
Doctrine_Association
)
{
}
elseif
(
$fk
instanceof
Doctrine_
Relation_
Association
)
{
$asf
=
$fk
->
getAssociationFactory
();
$assocTableName
=
$asf
->
getTableName
();
...
...
lib/Doctrine/Record.php
View file @
ed62d636
...
...
@@ -742,8 +742,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$rel
=
$this
->
table
->
getRelation
(
$name
);
// one-to-many or one-to-one relation
if
(
$rel
instanceof
Doctrine_ForeignKey
||
$rel
instanceof
Doctrine_LocalKey
)
{
if
(
$rel
instanceof
Doctrine_
Relation_
ForeignKey
||
$rel
instanceof
Doctrine_
Relation_
LocalKey
)
{
switch
(
$rel
->
getType
())
{
case
Doctrine_Relation
::
MANY_COMPOSITE
:
case
Doctrine_Relation
::
MANY_AGGREGATE
:
...
...
@@ -767,7 +767,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
break
;
}
}
elseif
(
$rel
instanceof
Doctrine_Association
)
{
}
elseif
(
$rel
instanceof
Doctrine_
Relation_
Association
)
{
// join table relation found
if
(
!
(
$value
instanceof
Doctrine_Collection
))
throw
new
Doctrine_Record_Exception
(
"Couldn't call Doctrine::set(), second argument should be an instance of Doctrine_Collection when setting one-to-many references."
);
...
...
@@ -979,11 +979,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$name
=
$table
->
getComponentName
();
$alias
=
$this
->
table
->
getAlias
(
$name
);
if
(
$fk
instanceof
Doctrine_Association
)
{
if
(
$fk
instanceof
Doctrine_
Relation_
Association
)
{
switch
(
$fk
->
getType
())
:
case
Doctrine_Relation
::
MANY_COMPOSITE
:
break
;
case
Doctrine_Relation
::
MANY_AGGREGATE
:
$asf
=
$fk
->
getAssociationFactory
();
...
...
@@ -1015,8 +1012,8 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
}
break
;
endswitch
;
}
elseif
(
$fk
instanceof
Doctrine_ForeignKey
||
$fk
instanceof
Doctrine_LocalKey
)
{
}
elseif
(
$fk
instanceof
Doctrine_
Relation_
ForeignKey
||
$fk
instanceof
Doctrine_
Relation_
LocalKey
)
{
switch
(
$fk
->
getType
())
:
case
Doctrine_Relation
::
ONE_COMPOSITE
:
...
...
@@ -1168,7 +1165,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
return
false
;
if
(
!
$connector
->
isOneToOne
())
{
if
(
!
(
$connector
instanceof
Doctrine_Association
))
if
(
!
(
$connector
instanceof
Doctrine_
Relation_
Association
))
$coll
->
setReference
(
$this
,
$connector
);
$this
->
references
[
$alias
]
=
$coll
;
...
...
@@ -1216,7 +1213,6 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return void
*/
final
public
function
loadReference
(
$name
)
{
$fk
=
$this
->
table
->
getRelation
(
$name
);
if
(
$fk
->
isOneToOne
())
{
...
...
lib/Doctrine/Relation/Association.php
0 → 100644
View file @
ed62d636
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Relation_Association this class takes care of association mapping
* (= many-to-many relationships, where the relationship is handled with an additional relational table
* which holds 2 foreign keys)
*
*
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @license LGPL
*/
class
Doctrine_Relation_Association
extends
Doctrine_Relation
{
/**
* @var Doctrine_Table $associationTable
*/
protected
$associationTable
;
/**
* the constructor
* @param Doctrine_Table $table foreign factory object
* @param Doctrine_Table $associationTable factory which handles the association
* @param string $local local field name
* @param string $foreign foreign field name
* @param integer $type type of relation
* @see Doctrine_Table constants
*/
public
function
__construct
(
Doctrine_Table
$table
,
Doctrine_Table
$associationTable
,
$local
,
$foreign
,
$type
,
$alias
)
{
parent
::
__construct
(
$table
,
$local
,
$foreign
,
$type
,
$alias
);
$this
->
associationTable
=
$associationTable
;
}
/**
* @return Doctrine_Table
*/
public
function
getAssociationFactory
()
{
return
$this
->
associationTable
;
}
/**
* getRelationDql
*
* @param integer $count
* @return string
*/
public
function
getRelationDql
(
$count
,
$context
=
'record'
)
{
switch
(
$context
)
:
case
"record"
:
$sub
=
"SELECT "
.
$this
->
foreign
.
" FROM "
.
$this
->
associationTable
->
getTableName
()
.
" WHERE "
.
$this
->
local
.
" IN ("
.
substr
(
str_repeat
(
"?, "
,
$count
),
0
,
-
2
)
.
")"
;
$dql
=
"FROM "
.
$this
->
table
->
getComponentName
();
$dql
.=
"."
.
$this
->
associationTable
->
getComponentName
();
$dql
.=
" WHERE "
.
$this
->
table
->
getComponentName
()
.
"."
.
$this
->
table
->
getIdentifier
()
.
" IN (
$sub
)"
;
break
;
case
"collection"
:
$sub
=
substr
(
str_repeat
(
"?, "
,
$count
),
0
,
-
2
);
$dql
=
"FROM "
.
$this
->
associationTable
->
getComponentName
()
.
"."
.
$this
->
table
->
getComponentName
();
$dql
.=
" WHERE "
.
$this
->
associationTable
->
getComponentName
()
.
"."
.
$this
->
local
.
" IN (
$sub
)"
;
endswitch
;
return
$dql
;
}
/**
* fetchRelatedFor
*
* fetches a component related to given record
*
* @param Doctrine_Record $record
* @return Doctrine_Record|Doctrine_Collection
*/
public
function
fetchRelatedFor
(
Doctrine_Record
$record
)
{
$id
=
$record
->
getIncremented
();
if
(
empty
(
$id
))
$coll
=
new
Doctrine_Collection
(
$this
->
table
);
else
$coll
=
Doctrine_Query
::
create
()
->
parseQuery
(
$this
->
getRelationDql
(
1
))
->
execute
(
array
(
$id
));
return
$coll
;
}
}
lib/Doctrine/Relation/Association/Self.php
0 → 100644
View file @
ed62d636
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
class
Doctrine_Relation_Association_Self
extends
Doctrine_Relation_Association
{
/**
* getRelationDql
*
* @param integer $count
* @return string
*/
public
function
getRelationDql
(
$count
,
$context
=
'record'
)
{
switch
(
$context
)
:
case
"record"
:
$sub
=
"SELECT "
.
$this
->
foreign
.
" FROM "
.
$this
->
associationTable
->
getTableName
()
.
" WHERE "
.
$this
->
local
.
" = ?"
;
$sub2
=
"SELECT "
.
$this
->
local
.
" FROM "
.
$this
->
associationTable
->
getTableName
()
.
" WHERE "
.
$this
->
foreign
.
" = ?"
;
$dql
=
"FROM "
.
$this
->
table
->
getComponentName
();
$dql
.=
"."
.
$this
->
associationTable
->
getComponentName
();
$dql
.=
" WHERE "
.
$this
->
table
->
getComponentName
()
.
"."
.
$this
->
table
->
getIdentifier
()
.
" IN (
$sub
)"
;
$dql
.=
" || "
.
$this
->
table
->
getComponentName
()
.
"."
.
$this
->
table
->
getIdentifier
()
.
" IN (
$sub2
)"
;
break
;
case
"collection"
:
$sub
=
substr
(
str_repeat
(
"?, "
,
$count
),
0
,
-
2
);
$dql
=
"FROM "
.
$this
->
associationTable
->
getComponentName
()
.
"."
.
$this
->
table
->
getComponentName
();
$dql
.=
" WHERE "
.
$this
->
associationTable
->
getComponentName
()
.
"."
.
$this
->
local
.
" IN (
$sub
)"
;
endswitch
;
return
$dql
;
}
public
function
fetchRelatedFor
(
Doctrine_Record
$record
)
{
$id
=
$record
->
getIncremented
();
$q
=
new
Doctrine_RawSql
();
$assocTable
=
$this
->
getAssociationFactory
()
->
getTableName
();
$tableName
=
$record
->
getTable
()
->
getTableName
();
$identifier
=
$record
->
getTable
()
->
getIdentifier
();
$sub
=
"SELECT "
.
$this
->
getForeign
()
.
" FROM "
.
$assocTable
.
" WHERE "
.
$this
->
getLocal
()
.
" = ?"
;
$sub2
=
"SELECT "
.
$this
->
getLocal
()
.
" FROM "
.
$assocTable
.
" WHERE "
.
$this
->
getForeign
()
.
" = ?"
;
$q
->
select
(
'{'
.
$tableName
.
'.*}, {'
.
$assocTable
.
'.*}'
)
->
from
(
$tableName
.
' INNER JOIN '
.
$assocTable
.
' ON '
.
$tableName
.
'.'
.
$identifier
.
' = '
.
$assocTable
.
'.'
.
$this
->
getLocal
()
.
' OR '
.
$tableName
.
'.'
.
$identifier
.
' = '
.
$assocTable
.
'.'
.
$this
->
getForeign
()
)
->
where
(
$tableName
.
'.'
.
$identifier
.
' IN ('
.
$sub
.
') OR '
.
$tableName
.
'.'
.
$identifier
.
' IN ('
.
$sub2
.
')'
);
$q
->
addComponent
(
$tableName
,
$record
->
getTable
()
->
getComponentName
());
$q
->
addComponent
(
$assocTable
,
$record
->
getTable
()
->
getComponentName
()
.
'.'
.
$this
->
getAssociationFactory
()
->
getComponentName
());
return
$q
->
execute
(
array
(
$id
,
$id
));
}
}
?>
lib/Doctrine/Relation/ForeignKey.php
0 → 100644
View file @
ed62d636
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine
::
autoload
(
'Doctrine_Relation'
);
/**
* Doctrine_Relation_ForeignKey
* This class represents a foreign key relation
*
* @author Konsta Vesterinen
* @license LGPL
* @package Doctrine
*/
class
Doctrine_Relation_ForeignKey
extends
Doctrine_Relation
{
/**
* fetchRelatedFor
*
* fetches a component related to given record
*
* @param Doctrine_Record $record
* @return Doctrine_Record|Doctrine_Collection
*/
public
function
fetchRelatedFor
(
Doctrine_Record
$record
)
{
$id
=
$record
->
get
(
$this
->
local
);
if
(
$this
->
isOneToOne
())
{
if
(
empty
(
$id
))
{
$related
=
$this
->
table
->
create
();
}
else
{
$dql
=
"FROM "
.
$this
->
table
->
getComponentName
()
.
" WHERE "
.
$this
->
table
->
getComponentName
()
.
"."
.
$this
->
foreign
.
" = ?"
;
$coll
=
$this
->
table
->
getConnection
()
->
query
(
$dql
,
array
(
$id
));
$related
=
$coll
[
0
];
}
$related
->
set
(
$this
->
foreign
,
$record
,
false
);
}
else
{
if
(
empty
(
$id
))
{
$related
=
new
Doctrine_Collection
(
$this
->
table
);
}
else
{
$query
=
$this
->
getRelationDql
(
1
);
$related
=
$this
->
table
->
getConnection
()
->
query
(
$query
,
array
(
$id
));
}
$related
->
setReference
(
$record
,
$this
);
}
return
$related
;
}
}
lib/Doctrine/Relation/LocalKey.php
0 → 100644
View file @
ed62d636
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
Doctrine
::
autoload
(
'Doctrine_Relation'
);
/**
* Doctrine_Relation_LocalKey
* This class represents a local key relation
*
* @author Konsta Vesterinen
* @license LGPL
* @package Doctrine
*/
class
Doctrine_Relation_LocalKey
extends
Doctrine_Relation
{
/**
* fetchRelatedFor
*
* fetches a component related to given record
*
* @param Doctrine_Record $record
* @return Doctrine_Record|Doctrine_Collection
*/
public
function
fetchRelatedFor
(
Doctrine_Record
$record
)
{
$id
=
$record
->
get
(
$this
->
local
);
if
(
empty
(
$id
))
$related
=
$this
->
table
->
create
();
else
{
if
(
!
(
$related
=
$this
->
table
->
find
(
$id
)))
$related
=
$this
->
table
->
create
();
}
$record
->
set
(
$this
->
local
,
$related
,
false
);
return
$related
;
}
}
lib/Doctrine/Session.php
View file @
ed62d636
...
...
@@ -274,7 +274,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
// group relations
foreach
(
$rels
as
$key
=>
$rel
)
{
if
(
$rel
instanceof
Doctrine_ForeignKey
)
{
if
(
$rel
instanceof
Doctrine_
Relation_
ForeignKey
)
{
unset
(
$rels
[
$key
]);
array_unshift
(
$rels
,
$rel
);
}
...
...
@@ -289,7 +289,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
if
(
$name
===
$nm
)
continue
;
if
(
$rel
instanceof
Doctrine_ForeignKey
)
{
if
(
$rel
instanceof
Doctrine_
Relation_
ForeignKey
)
{
if
(
$index2
!==
false
)
{
if
(
$index2
>=
$index
)
continue
;
...
...
@@ -305,7 +305,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
//print "$k -- adding $nm :$name...<br>";
}
}
elseif
(
$rel
instanceof
Doctrine_LocalKey
)
{
}
elseif
(
$rel
instanceof
Doctrine_
Relation_
LocalKey
)
{
if
(
$index2
!==
false
)
{
if
(
$index2
<=
$index
)
continue
;
...
...
@@ -322,7 +322,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
//print "$k -- pushing <b>$name</b> into 0...<br \>";
}
}
elseif
(
$rel
instanceof
Doctrine_Association
)
{
}
elseif
(
$rel
instanceof
Doctrine_
Relation_
Association
)
{
$t
=
$rel
->
getAssociationFactory
();
$n
=
$t
->
getComponentName
();
...
...
@@ -715,8 +715,8 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
$saveLater
=
array
();
foreach
(
$record
->
getReferences
()
as
$k
=>
$v
)
{
$fk
=
$record
->
getTable
()
->
getRelation
(
$k
);
if
(
$fk
instanceof
Doctrine_ForeignKey
||
$fk
instanceof
Doctrine_LocalKey
)
{
if
(
$fk
instanceof
Doctrine_
Relation_
ForeignKey
||
$fk
instanceof
Doctrine_
Relation_
LocalKey
)
{
switch
(
$fk
->
getType
())
:
case
Doctrine_Relation
::
ONE_COMPOSITE
:
case
Doctrine_Relation
::
MANY_COMPOSITE
:
...
...
@@ -744,7 +744,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
}
break
;
endswitch
;
}
elseif
(
$fk
instanceof
Doctrine_Association
)
{
}
elseif
(
$fk
instanceof
Doctrine_
Relation_
Association
)
{
$v
->
save
();
}
}
...
...
lib/Doctrine/Table.php
View file @
ed62d636
...
...
@@ -609,7 +609,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
if
(
!
isset
(
$local
))
$local
=
$table
->
getIdentifier
();
$relation
=
new
Doctrine_LocalKey
(
$table
,
$foreign
,
$local
,
$type
,
$alias
);
$relation
=
new
Doctrine_
Relation_
LocalKey
(
$table
,
$foreign
,
$local
,
$type
,
$alias
);
}
else
throw
new
Doctrine_Table_Exception
(
"Only one-to-one relations are possible when local reference key is used."
);
...
...
@@ -620,7 +620,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$local
=
$this
->
identifier
;
// ONE-TO-MANY or ONE-TO-ONE
$relation
=
new
Doctrine_ForeignKey
(
$table
,
$local
,
$foreign
,
$type
,
$alias
);
$relation
=
new
Doctrine_
Relation_
ForeignKey
(
$table
,
$local
,
$foreign
,
$type
,
$alias
);
}
else
{
// MANY-TO-MANY
...
...
@@ -651,9 +651,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
if
(
count
(
$fields
)
>
1
)
{
// SELF-REFERENCING THROUGH JOIN TABLE
$this
->
relations
[
$e2
[
0
]]
=
new
Doctrine_ForeignKey
(
$associationTable
,
$local
,
$fields
[
0
],
Doctrine_Relation
::
MANY_COMPOSITE
,
$e2
[
0
]);
$this
->
relations
[
$e2
[
0
]]
=
new
Doctrine_
Relation_
ForeignKey
(
$associationTable
,
$local
,
$fields
[
0
],
Doctrine_Relation
::
MANY_COMPOSITE
,
$e2
[
0
]);
$relation
=
new
Doctrine_Association_Self
(
$table
,
$associationTable
,
$fields
[
0
],
$fields
[
1
],
$type
,
$alias
);
$relation
=
new
Doctrine_
Relation_
Association_Self
(
$table
,
$associationTable
,
$fields
[
0
],
$fields
[
1
],
$type
,
$alias
);
}
else
{
// auto initialize a new one-to-one relationship for association table
...
...
@@ -661,9 +661,9 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
$associationTable
->
bind
(
$table
->
getComponentName
(),
$associationTable
->
getComponentName
()
.
'.'
.
$foreign
,
Doctrine_Relation
::
ONE_AGGREGATE
,
'id'
);
// NORMAL MANY-TO-MANY RELATIONSHIP
$this
->
relations
[
$e2
[
0
]]
=
new
Doctrine_ForeignKey
(
$associationTable
,
$local
,
$e2
[
1
],
Doctrine_Relation
::
MANY_COMPOSITE
,
$e2
[
0
]);
$this
->
relations
[
$e2
[
0
]]
=
new
Doctrine_
Relation_
ForeignKey
(
$associationTable
,
$local
,
$e2
[
1
],
Doctrine_Relation
::
MANY_COMPOSITE
,
$e2
[
0
]);
$relation
=
new
Doctrine_Association
(
$table
,
$associationTable
,
$e2
[
1
],
$foreign
,
$type
,
$alias
);
$relation
=
new
Doctrine_
Relation_
Association
(
$table
,
$associationTable
,
$e2
[
1
],
$foreign
,
$type
,
$alias
);
}
}
...
...
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