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
7119471b
Commit
7119471b
authored
Jul 27, 2006
by
doctrine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Doctrine_Collection::loadRelated() added
parent
3cd669ad
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
453 additions
and
12 deletions
+453
-12
Access.php
Doctrine/Access.php
+19
-0
Collection.php
Doctrine/Collection.php
+101
-2
Configurable.php
Doctrine/Configurable.php
+19
-0
DB.php
Doctrine/DB.php
+19
-0
Hydrate.php
Doctrine/Hydrate.php
+9
-0
Lib.php
Doctrine/Lib.php
+28
-0
Manager.php
Doctrine/Manager.php
+19
-0
Query.php
Doctrine/Query.php
+19
-1
RawSql.php
Doctrine/RawSql.php
+27
-0
Record.php
Doctrine/Record.php
+21
-8
Relation.php
Doctrine/Relation.php
+20
-0
Session.php
Doctrine/Session.php
+19
-1
CollectionTestCase.php
tests/CollectionTestCase.php
+116
-0
classes.php
tests/classes.php
+14
-0
run.php
tests/run.php
+3
-0
No files found.
Doctrine/Access.php
View file @
7119471b
<?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_Access
*
...
...
Doctrine/Collection.php
View file @
7119471b
...
...
@@ -280,7 +280,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$query
=
"SELECT "
.
$foreign
.
" FROM "
.
$asf
->
getTableName
()
.
" WHERE "
.
$local
.
"="
.
$this
->
getIncremented
();
$table
=
$fk
->
getTable
();
$graph
=
new
Doctrine_
DQL_Parser
(
$table
->
getSession
());
$graph
=
new
Doctrine_
Query
(
$table
->
getSession
());
$q
=
"FROM "
.
$table
->
getComponentName
()
.
" WHERE "
.
$table
->
getComponentName
()
.
"."
.
$table
->
getIdentifier
()
.
" IN (
$query
)"
;
...
...
@@ -485,6 +485,105 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
}
}
}
/**
* loadRelated
*
* @param string $name
*/
public
function
loadRelated
(
$name
)
{
$rel
=
$this
->
table
->
getForeignKey
(
$name
);
$table
=
$rel
->
getTable
();
$query
=
new
Doctrine_Query
(
$this
->
table
->
getSession
());
$foreign
=
$rel
->
getForeign
();
$local
=
$rel
->
getLocal
();
$list
=
array
();
if
(
$rel
instanceof
Doctrine_LocalKey
||
$rel
instanceof
Doctrine_ForeignKey
)
{
foreach
(
$this
->
data
as
$record
)
:
$list
[]
=
$record
[
$local
];
endforeach
;
}
else
{
foreach
(
$this
->
data
as
$record
)
:
$value
=
$record
->
getIncremented
();
if
(
$value
!==
null
)
$list
[]
=
$value
;
endforeach
;
}
$paramStr
=
"("
.
substr
(
str_repeat
(
"?, "
,
count
(
$list
)),
0
,
-
2
)
.
")"
;
$multi
=
true
;
if
(
$rel
instanceof
Doctrine_LocalKey
||
$rel
instanceof
Doctrine_ForeignKey
)
$dql
=
"FROM "
.
$table
->
getComponentName
()
.
" WHERE "
.
$table
->
getComponentName
()
.
"."
.
$rel
->
getForeign
()
.
" IN "
.
$paramStr
;
if
(
$rel
instanceof
Doctrine_LocalKey
)
{
$multi
=
false
;
}
elseif
(
$rel
instanceof
Doctrine_Association
)
{
$asf
=
$rel
->
getAssociationFactory
();
$sub
=
"SELECT "
.
$foreign
.
" FROM "
.
$asf
->
getTableName
()
.
" WHERE "
.
$local
.
" IN "
.
$paramStr
;
$dql
=
"FROM "
.
$table
->
getComponentName
()
.
":"
.
$asf
->
getComponentName
()
.
" WHERE "
.
$table
->
getComponentName
()
.
"."
.
$table
->
getIdentifier
()
.
" IN (
$sub
)"
;
//$query->parseQuery($dql);
//print Doctrine_Lib::formatSql($query->getQuery());
}
$coll
=
$query
->
query
(
$dql
,
$list
);
if
(
$rel
instanceof
Doctrine_LocalKey
)
{
foreach
(
$this
->
data
as
$key
=>
$record
)
{
foreach
(
$coll
as
$k
=>
$related
)
{
if
(
$related
[
$foreign
]
==
$record
[
$local
])
{
$this
->
data
[
$key
]
->
setRelated
(
$name
,
$related
);
}
}
}
}
elseif
(
$rel
instanceof
Doctrine_ForeignKey
)
{
foreach
(
$this
->
data
as
$key
=>
$record
)
{
if
(
$record
->
getState
()
==
Doctrine_Record
::
STATE_TCLEAN
||
$record
->
getState
()
==
Doctrine_Record
::
STATE_TDIRTY
)
continue
;
$sub
=
new
Doctrine_Collection
(
$table
);
foreach
(
$coll
as
$k
=>
$related
)
{
if
(
$related
[
$foreign
]
==
$record
[
$local
])
{
$sub
->
add
(
$related
);
$coll
->
remove
(
$k
);
}
}
$this
->
data
[
$key
]
->
setRelated
(
$name
,
$sub
);
}
}
elseif
(
$rel
instanceof
Doctrine_Association
)
{
$identifier
=
$this
->
table
->
getIdentifier
();
foreach
(
$this
->
data
as
$key
=>
$record
)
{
if
(
$record
->
getState
()
==
Doctrine_Record
::
STATE_TCLEAN
||
$record
->
getState
()
==
Doctrine_Record
::
STATE_TDIRTY
)
continue
;
$sub
=
new
Doctrine_Collection
(
$table
);
$association
=
$asf
->
getComponentName
();
foreach
(
$coll
as
$k
=>
$related
)
{
if
(
$related
[
$association
][
0
]
->
get
(
$local
)
==
$record
[
$identifier
])
{
$sub
->
add
(
$related
);
$coll
->
remove
(
$k
);
}
}
$this
->
data
[
$key
]
->
setRelated
(
$name
,
$sub
);
}
}
}
/**
* getNormalIterator
* returns normal iterator - an iterator that will not expand this collection
...
...
Doctrine/Configurable.php
View file @
7119471b
<?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_Configurable
* the base for Doctrine_Table, Doctrine_Manager and Doctrine_Session
...
...
Doctrine/DB.php
View file @
7119471b
<?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_DB
extends
PDO
implements
Countable
,
IteratorAggregate
{
/**
* default DSN
...
...
Doctrine/Hydrate.php
View file @
7119471b
...
...
@@ -65,6 +65,15 @@ class Doctrine_Hydrate extends Doctrine_Access {
public
function
__construct
(
Doctrine_Session
$session
)
{
$this
->
session
=
$session
;
}
public
function
remove
(
$name
)
{
if
(
isset
(
$this
->
parts
[
$name
]))
{
if
(
$name
==
"limit"
||
$name
==
"offset"
)
$this
->
parts
[
$name
]
=
false
;
else
$this
->
parts
[
$name
]
=
array
();
}
return
$this
;
}
/**
* clear
* resets all the variables
...
...
Doctrine/Lib.php
View file @
7119471b
<?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>.
*/
/**
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @license LGPL
*
* Doctrine_Lib has not commonly used static functions, mostly for debugging purposes
*/
class
Doctrine_Lib
{
/**
* @param integer $state the state of record
...
...
@@ -131,6 +158,7 @@ class Doctrine_Lib {
$l
=
str_replace
(
"SELECT"
,
"<font color='
$color
'><b>SELECT</b></font><br \> "
,
$l
);
$l
=
str_replace
(
"FROM"
,
"<font color='
$color
'><b>FROM</b></font><br \>"
,
$l
);
$l
=
str_replace
(
"LEFT JOIN"
,
"<br \><font color='
$color
'><b>LEFT JOIN</b></font>"
,
$l
);
$l
=
str_replace
(
"INNER JOIN"
,
"<br \><font color='
$color
'><b>INNER JOIN</b></font>"
,
$l
);
$l
=
str_replace
(
"WHERE"
,
"<br \><font color='
$color
'><b>WHERE</b></font>"
,
$l
);
$l
=
str_replace
(
"GROUP BY"
,
"<br \><font color='
$color
'><b>GROUP BY</b></font>"
,
$l
);
$l
=
str_replace
(
"HAVING"
,
"<br \><font color='
$color
'><b>HAVING</b></font>"
,
$l
);
...
...
Doctrine/Manager.php
View file @
7119471b
<?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>.
*/
require_once
(
"Configurable.php"
);
require_once
(
"EventListener.php"
);
/**
...
...
Doctrine/Query.php
View file @
7119471b
<?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>.
*/
require_once
(
"Access.php"
);
/**
* Doctrine_Query
...
...
@@ -6,7 +25,6 @@ require_once("Access.php");
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @license LGPL
* @version 1.0 alpha
*/
class
Doctrine_Query
extends
Doctrine_Hydrate
{
...
...
Doctrine/RawSql.php
View file @
7119471b
<?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>.
*/
require_once
(
"Hydrate.php"
);
/**
* Doctrine_RawSql
*
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @license LGPL
*/
class
Doctrine_RawSql
extends
Doctrine_Hydrate
{
/**
* @var array $fields
...
...
Doctrine/Record.php
View file @
7119471b
...
...
@@ -615,8 +615,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @return boolean
*/
public
function
has
(
$name
)
{
if
(
isset
(
$this
->
data
[
$name
])
OR
isset
(
$this
->
id
[
$name
]))
if
(
isset
(
$this
->
data
[
$name
])
||
isset
(
$this
->
id
[
$name
]))
return
true
;
return
$this
->
table
->
hasForeignKey
(
$name
);
}
/**
...
...
@@ -1036,10 +1037,22 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
public
function
getReferences
()
{
return
$this
->
references
;
}
/**
* setRelated
*
* @param string $alias
* @param Doctrine_Access $coll
*/
final
public
function
setRelated
(
$alias
,
Doctrine_Access
$coll
)
{
$this
->
references
[
$alias
]
=
$coll
;
$this
->
originals
[
$alias
]
=
$coll
;
}
/**
* loadReference
* loads a related component
*
* @throws InvalidKeyException
* @param name
* @param
string $
name
* @return void
*/
final
public
function
loadReference
(
$name
)
{
...
...
@@ -1152,15 +1165,15 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* filterRelated
* lazy initializes a new filter instance for given related component
*
* @param $component
Name name
of the related component
* @param $component
Alias alias
of the related component
* @return Doctrine_Filter
*/
final
public
function
filterRelated
(
$component
Name
)
{
if
(
!
isset
(
$this
->
filters
[
$component
Name
]))
{
$this
->
filters
[
$component
Name
]
=
new
Doctrine_Filter
(
$componentName
);
final
public
function
filterRelated
(
$component
Alias
)
{
if
(
!
isset
(
$this
->
filters
[
$component
Alias
]))
{
$this
->
filters
[
$component
Alias
]
=
new
Doctrine_Filter
(
$componentAlias
);
}
return
$this
->
filters
[
$component
Name
];
return
$this
->
filters
[
$component
Alias
];
}
/**
* sets enumerated value array for given field
...
...
Doctrine/Relation.php
View file @
7119471b
<?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
* This class represents a relation between components
*
* @package Doctrine ORM
* @url www.phpdoctrine.com
...
...
Doctrine/Session.php
View file @
7119471b
<?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>.
*/
require_once
(
"Configurable.php"
);
require_once
(
"Record.php"
);
/**
...
...
@@ -7,7 +26,6 @@ require_once("Record.php");
* @package Doctrine ORM
* @url www.phpdoctrine.com
* @license LGPL
* @version 1.0 alpha
*/
abstract
class
Doctrine_Session
extends
Doctrine_Configurable
implements
Countable
,
IteratorAggregate
{
/**
...
...
tests/CollectionTestCase.php
View file @
7119471b
...
...
@@ -14,7 +14,123 @@ class Doctrine_CollectionTestCase extends Doctrine_UnitTestCase {
$this
->
assertTrue
(
$coll
->
count
(),
3
);
$this
->
assertEqual
(
$coll
->
getKeys
(),
array
(
0
,
1
,
2
));
}
public
function
testLoadRelatedForAssociation
()
{
$coll
=
$this
->
session
->
query
(
"FROM User"
);
$this
->
assertEqual
(
$coll
->
count
(),
8
);
$coll
[
0
]
->
Group
[
1
]
->
name
=
"Actors House 2"
;
$coll
[
0
]
->
Group
[
2
]
->
name
=
"Actors House 3"
;
$coll
[
2
]
->
Group
[
0
]
->
name
=
"Actors House 4"
;
$coll
[
2
]
->
Group
[
1
]
->
name
=
"Actors House 5"
;
$coll
[
2
]
->
Group
[
2
]
->
name
=
"Actors House 6"
;
$coll
[
5
]
->
Group
[
0
]
->
name
=
"Actors House 7"
;
$coll
[
5
]
->
Group
[
1
]
->
name
=
"Actors House 8"
;
$coll
[
5
]
->
Group
[
2
]
->
name
=
"Actors House 9"
;
$coll
->
save
();
$this
->
session
->
clear
();
$coll
=
$this
->
session
->
query
(
"FROM User"
);
$this
->
assertEqual
(
$coll
->
count
(),
8
);
$this
->
assertEqual
(
$coll
[
0
]
->
Group
->
count
(),
2
);
$this
->
assertEqual
(
$coll
[
1
]
->
Group
->
count
(),
1
);
$this
->
assertEqual
(
$coll
[
2
]
->
Group
->
count
(),
3
);
$this
->
assertEqual
(
$coll
[
5
]
->
Group
->
count
(),
3
);
$this
->
session
->
clear
();
$coll
=
$this
->
session
->
query
(
"FROM User"
);
$this
->
assertEqual
(
$coll
->
count
(),
8
);
$count
=
$this
->
dbh
->
count
();
$coll
->
loadRelated
(
"Group"
);
$this
->
assertEqual
((
$count
+
1
),
$this
->
dbh
->
count
());
$this
->
assertEqual
(
$coll
[
0
]
->
Group
->
count
(),
2
);
$this
->
assertEqual
((
$count
+
1
),
$this
->
dbh
->
count
());
$this
->
assertEqual
(
$coll
[
1
]
->
Group
->
count
(),
1
);
$this
->
assertEqual
((
$count
+
1
),
$this
->
dbh
->
count
());
$this
->
assertEqual
(
$coll
[
2
]
->
Group
->
count
(),
3
);
$this
->
assertEqual
((
$count
+
1
),
$this
->
dbh
->
count
());
$this
->
assertEqual
(
$coll
[
5
]
->
Group
->
count
(),
3
);
$this
->
assertEqual
((
$count
+
1
),
$this
->
dbh
->
count
());
$this
->
session
->
clear
();
}
public
function
testLoadRelatedForLocalKeyRelation
()
{
$coll
=
$this
->
session
->
query
(
"FROM User"
);
$this
->
assertEqual
(
$coll
->
count
(),
8
);
$count
=
$this
->
dbh
->
count
();
$coll
->
loadRelated
(
"Email"
);
$this
->
assertEqual
((
$count
+
1
),
$this
->
dbh
->
count
());
$this
->
assertEqual
(
$coll
[
0
]
->
Email
->
address
,
"zYne@example.com"
);
$this
->
assertEqual
((
$count
+
1
),
$this
->
dbh
->
count
());
$this
->
assertEqual
(
$coll
[
2
]
->
Email
->
address
,
"caine@example.com"
);
$this
->
assertEqual
(
$coll
[
3
]
->
Email
->
address
,
"kitano@example.com"
);
$this
->
assertEqual
(
$coll
[
4
]
->
Email
->
address
,
"stallone@example.com"
);
$this
->
assertEqual
((
$count
+
1
),
$this
->
dbh
->
count
());
$this
->
session
->
clear
();
}
public
function
testLoadRelatedForForeignKey
()
{
$coll
=
$this
->
session
->
query
(
"FROM User"
);
$this
->
assertEqual
(
$coll
->
count
(),
8
);
$count
=
$this
->
dbh
->
count
();
$coll
->
loadRelated
(
"Phonenumber"
);
$this
->
assertEqual
((
$count
+
1
),
$this
->
dbh
->
count
());
$this
->
assertEqual
(
$coll
[
0
]
->
Phonenumber
[
0
]
->
phonenumber
,
"123 123"
);
$this
->
assertEqual
((
$count
+
1
),
$this
->
dbh
->
count
());
$coll
[
0
]
->
Phonenumber
[
1
]
->
phonenumber
;
$this
->
assertEqual
((
$count
+
1
),
$this
->
dbh
->
count
());
$this
->
assertEqual
(
$coll
[
4
]
->
Phonenumber
[
0
]
->
phonenumber
,
"111 555 333"
);
$this
->
assertEqual
(
$coll
[
4
][
"Phonenumber"
][
1
]
->
phonenumber
,
"123 213"
);
$this
->
assertEqual
(
$coll
[
4
][
"Phonenumber"
][
2
]
->
phonenumber
,
"444 555"
);
$this
->
assertEqual
(
$coll
[
5
]
->
Phonenumber
[
0
]
->
phonenumber
,
"111 222 333"
);
$this
->
assertEqual
(
$coll
[
6
]
->
Phonenumber
[
0
]
->
phonenumber
,
"111 222 333"
);
$this
->
assertEqual
(
$coll
[
6
][
"Phonenumber"
][
1
]
->
phonenumber
,
"222 123"
);
$this
->
assertEqual
(
$coll
[
6
][
"Phonenumber"
][
2
]
->
phonenumber
,
"123 456"
);
$this
->
assertEqual
((
$count
+
1
),
$this
->
dbh
->
count
());
$this
->
session
->
clear
();
}
public
function
testCount
()
{
$coll
=
new
Doctrine_Collection
(
$this
->
session
->
getTable
(
'User'
));
$this
->
assertEqual
(
$coll
->
count
(),
0
);
$coll
[
0
];
$this
->
assertEqual
(
$coll
->
count
(),
1
);
}
public
function
testExpand
()
{
$users
=
$this
->
session
->
query
(
"FROM User-b.Phonenumber-l WHERE User.Phonenumber.phonenumber LIKE '%123%'"
);
...
...
tests/classes.php
View file @
7119471b
...
...
@@ -319,6 +319,20 @@ class EnumTest extends Doctrine_Record {
$this
->
setEnumValues
(
"status"
,
array
(
"open"
,
"verified"
,
"closed"
));
}
}
class
FilterTest
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
100
);
}
public
function
setUp
()
{
$this
->
ownsMany
(
"FilterTest2 as filtered"
,
"FilterTest2.test1_id"
);
}
}
class
FilterTest2
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
100
);
$this
->
hasColumn
(
"test1_id"
,
"integer"
);
}
}
class
CustomPK
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"uid"
,
"integer"
,
11
,
"autoincrement|primary"
);
...
...
tests/run.php
View file @
7119471b
...
...
@@ -21,6 +21,7 @@ require_once("CacheQuerySqliteTestCase.php");
require_once
(
"ViewTestCase.php"
);
require_once
(
"RawSqlTestCase.php"
);
require_once
(
"CustomPrimaryKeyTestCase.php"
);
require_once
(
"FilterTestCase.php"
);
error_reporting
(
E_ALL
);
...
...
@@ -60,6 +61,8 @@ $test->addTestCase(new Doctrine_RawSql_TestCase());
$test
->
addTestCase
(
new
Doctrine_CustomPrimaryKeyTestCase
());
$test
->
addTestCase
(
new
Doctrine_Filter_TestCase
());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
...
...
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