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
da9d179d
Commit
da9d179d
authored
Sep 01, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for mapping table column values as collection indexes
parent
155f5193
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
85 additions
and
33 deletions
+85
-33
Collection.php
Doctrine/Collection.php
+33
-20
Configurable.php
Doctrine/Configurable.php
+0
-3
CollectionTestCase.php
tests/CollectionTestCase.php
+50
-7
run.php
tests/run.php
+2
-3
No files found.
Doctrine/Collection.php
View file @
da9d179d
...
@@ -57,9 +57,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
...
@@ -57,9 +57,9 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
*/
*/
protected
$expanded
=
array
();
protected
$expanded
=
array
();
/**
/**
* @var
mixed $generator
* @var
string $keyColumn
*/
*/
protected
$
generator
;
protected
$
keyColumn
;
/**
/**
* @var Doctrine_Null $null used for extremely fast SQL null value testing
* @var Doctrine_Null $null used for extremely fast SQL null value testing
*/
*/
...
@@ -80,7 +80,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
...
@@ -80,7 +80,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$name
=
$table
->
getAttribute
(
Doctrine
::
ATTR_COLL_KEY
);
$name
=
$table
->
getAttribute
(
Doctrine
::
ATTR_COLL_KEY
);
if
(
$name
!==
null
)
{
if
(
$name
!==
null
)
{
$this
->
generator
=
new
Doctrine_IndexGenerator
(
$name
)
;
$this
->
keyColumn
=
$name
;
}
}
}
}
/**
/**
...
@@ -137,7 +137,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
...
@@ -137,7 +137,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
$name
=
$this
->
table
->
getAttribute
(
Doctrine
::
ATTR_COLL_KEY
);
$name
=
$this
->
table
->
getAttribute
(
Doctrine
::
ATTR_COLL_KEY
);
if
(
$name
!==
null
)
{
if
(
$name
!==
null
)
{
$this
->
generator
=
new
Doctrine_IndexGenerator
(
$name
)
;
$this
->
keyColumn
=
$name
;
}
}
}
}
/**
/**
...
@@ -155,17 +155,21 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
...
@@ -155,17 +155,21 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
return
$this
->
expandable
;
return
$this
->
expandable
;
}
}
/**
/**
* @param Doctrine_IndexGenerator $generator
* setKeyColumn
*
* @param string $column
* @return void
* @return void
*/
*/
public
function
set
Generator
(
$generator
)
{
public
function
set
KeyColumn
(
$column
)
{
$this
->
generator
=
$generator
;
$this
->
keyColumn
=
$column
;
}
}
/**
/**
* @return Doctrine_IndexGenerator
* getKeyColumn
*
* @return string
*/
*/
public
function
get
Generator
()
{
public
function
get
KeyColumn
()
{
return
$this
->
generator
;
return
$this
->
column
;
}
}
/**
/**
* @return array
* @return array
...
@@ -450,9 +454,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
...
@@ -450,9 +454,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
return
true
;
return
true
;
}
}
if
(
isset
(
$this
->
generator
))
{
if
(
isset
(
$this
->
keyColumn
))
{
$key
=
$this
->
generator
->
getIndex
(
$record
);
$value
=
$record
->
get
(
$this
->
keyColumn
);
$this
->
data
[
$key
]
=
$record
;
if
(
$value
===
null
)
throw
new
Doctrine_Exception
(
"Couldn't create collection index. Record field '"
.
$this
->
keyColumn
.
"' was null."
);
$this
->
data
[
$value
]
=
$record
;
}
else
}
else
$this
->
data
[]
=
$record
;
$this
->
data
[]
=
$record
;
...
@@ -480,9 +487,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
...
@@ -480,9 +487,12 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
return
true
;
return
true
;
}
}
if
(
isset
(
$this
->
generator
))
{
if
(
isset
(
$this
->
keyColumn
))
{
$key
=
$this
->
generator
->
getIndex
(
$record
);
$value
=
$record
->
get
(
$this
->
keyColumn
);
$this
->
data
[
$key
]
=
$record
;
if
(
$value
===
null
)
throw
new
Doctrine_Exception
(
"Couldn't create collection index. Record field '"
.
$this
->
keyColumn
.
"' was null."
);
$this
->
data
[
$value
]
=
$record
;
}
else
}
else
$this
->
data
[]
=
$record
;
$this
->
data
[]
=
$record
;
...
@@ -510,11 +520,14 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
...
@@ -510,11 +520,14 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
}
elseif
(
$this
instanceof
Doctrine_Collection_Batch
)
{
}
elseif
(
$this
instanceof
Doctrine_Collection_Batch
)
{
$this
->
data
=
$query
->
getData
(
$name
);
$this
->
data
=
$query
->
getData
(
$name
);
if
(
isset
(
$this
->
generator
))
{
if
(
isset
(
$this
->
keyColumn
))
{
foreach
(
$this
->
data
as
$k
=>
$v
)
{
foreach
(
$this
->
data
as
$k
=>
$v
)
{
$record
=
$this
->
get
(
$k
);
$i
=
$this
->
generator
->
getIndex
(
$record
);
$value
=
$record
->
get
(
$this
->
keyColumn
);
$this
->
data
[
$i
]
=
$record
;
if
(
$value
===
null
)
throw
new
Doctrine_Exception
(
"Couldn't create collection index. Record field '"
.
$this
->
keyColumn
.
"' was null."
);
$this
->
data
[
$value
]
=
$record
;
unset
(
$this
->
data
[
$k
]);
unset
(
$this
->
data
[
$k
]);
}
}
}
}
...
...
Doctrine/Configurable.php
View file @
da9d179d
...
@@ -56,9 +56,6 @@ abstract class Doctrine_Configurable {
...
@@ -56,9 +56,6 @@ abstract class Doctrine_Configurable {
$dir
=
dirname
(
__FILE__
);
$dir
=
dirname
(
__FILE__
);
$value
=
$dir
.
substr
(
$value
,
6
);
$value
=
$dir
.
substr
(
$value
,
6
);
}
}
if
(
!
is_dir
(
$value
)
&&
!
file_exists
(
$value
))
mkdir
(
$value
,
0777
);
break
;
break
;
case
Doctrine
::
ATTR_CACHE_TTL
:
case
Doctrine
::
ATTR_CACHE_TTL
:
if
(
$value
<
1
)
if
(
$value
<
1
)
...
...
tests/CollectionTestCase.php
View file @
da9d179d
...
@@ -170,18 +170,14 @@ class Doctrine_CollectionTestCase extends Doctrine_UnitTestCase {
...
@@ -170,18 +170,14 @@ class Doctrine_CollectionTestCase extends Doctrine_UnitTestCase {
$this
->
assertEqual
(
$coll
[
2
]
->
getState
(),
Doctrine_Record
::
STATE_PROXY
);
$this
->
assertEqual
(
$coll
[
2
]
->
getState
(),
Doctrine_Record
::
STATE_PROXY
);
$generator
=
new
Doctrine_IndexGenerator
(
$this
->
objTable
->
getIdentifier
());
$coll
->
setGenerator
(
$generator
);
$coll
->
setKeyColumn
(
'id'
);
$generator
=
$coll
->
getGenerator
();
$user
=
$this
->
connection
->
getTable
(
"User"
)
->
find
(
4
);
$user
=
$this
->
connection
->
getTable
(
"User"
)
->
find
(
4
);
$this
->
assertEqual
(
$generator
->
getIndex
(
$user
),
4
);
}
}
public
function
testGenerator
()
{
public
function
testGenerator
()
{
$generator
=
new
Doctrine_IndexGenerator
(
"name"
);
$coll
=
new
Doctrine_Collection
(
$this
->
objTable
);
$coll
=
new
Doctrine_Collection
(
$this
->
objTable
);
$coll
->
set
Generator
(
$generator
);
$coll
->
set
KeyColumn
(
'name'
);
$user
=
new
User
();
$user
=
new
User
();
$user
->
name
=
"name"
;
$user
->
name
=
"name"
;
...
@@ -197,5 +193,52 @@ class Doctrine_CollectionTestCase extends Doctrine_UnitTestCase {
...
@@ -197,5 +193,52 @@ class Doctrine_CollectionTestCase extends Doctrine_UnitTestCase {
}
}
}
}
public
function
testFetchCollectionWithIdAsIndex
()
{
$user
=
new
User
();
$user
->
setAttribute
(
Doctrine
::
ATTR_COLL_KEY
,
'id'
);
$users
=
$user
->
getTable
()
->
findAll
();
$this
->
assertFalse
(
$users
->
contains
(
0
));
$this
->
assertEqual
(
$users
->
count
(),
8
);
$this
->
assertEqual
(
$users
[
0
]
->
getState
(),
Doctrine_Record
::
STATE_TCLEAN
);
$this
->
assertEqual
(
$users
[
4
]
->
getState
(),
Doctrine_Record
::
STATE_CLEAN
);
}
public
function
testFetchCollectionWithNameAsIndex
()
{
$user
=
new
User
();
$user
->
setAttribute
(
Doctrine
::
ATTR_COLL_KEY
,
'name'
);
$users
=
$user
->
getTable
()
->
findAll
();
$this
->
assertFalse
(
$users
->
contains
(
0
));
$this
->
assertEqual
(
$users
->
count
(),
8
);
$this
->
assertEqual
(
$users
[
0
]
->
getState
(),
Doctrine_Record
::
STATE_TCLEAN
);
$this
->
assertEqual
(
$users
[
'zYne'
]
->
getState
(),
Doctrine_Record
::
STATE_CLEAN
);
}
public
function
testFetchMultipleCollections
()
{
$this
->
connection
->
clear
();
$user
=
new
User
();
$user
->
setAttribute
(
Doctrine
::
ATTR_COLL_KEY
,
'id'
);
$phonenumber
=
new
Phonenumber
();
$phonenumber
->
setAttribute
(
Doctrine
::
ATTR_COLL_KEY
,
'id'
);
$q
=
new
Doctrine_Query
();
$users
=
$q
->
from
(
'User.Phonenumber'
)
->
execute
();
$this
->
assertFalse
(
$users
->
contains
(
0
));
$this
->
assertEqual
(
$users
->
count
(),
8
);
$this
->
assertEqual
(
$users
[
0
]
->
getState
(),
Doctrine_Record
::
STATE_TCLEAN
);
$this
->
assertEqual
(
$users
[
2
]
->
getState
(),
Doctrine_Record
::
STATE_TCLEAN
);
$this
->
assertEqual
(
$users
[
3
]
->
getState
(),
Doctrine_Record
::
STATE_TCLEAN
);
$this
->
assertEqual
(
$users
[
4
]
->
getState
(),
Doctrine_Record
::
STATE_CLEAN
);
$this
->
assertEqual
(
$users
[
4
]
->
name
,
'zYne'
);
$this
->
assertEqual
(
$users
[
4
]
->
Phonenumber
[
0
]
->
exists
(),
false
);
$this
->
assertEqual
(
$users
[
4
]
->
Phonenumber
[
0
]
->
getState
(),
Doctrine_Record
::
STATE_TDIRTY
);
$this
->
assertEqual
(
$users
[
4
]
->
Phonenumber
[
1
]
->
exists
(),
false
);
$this
->
assertEqual
(
$users
[
4
]
->
Phonenumber
[
2
]
->
getState
(),
Doctrine_Record
::
STATE_CLEAN
);
}
}
}
?>
?>
tests/run.php
View file @
da9d179d
...
@@ -62,9 +62,7 @@ $test->addTestCase(new Doctrine_Filter_TestCase());
...
@@ -62,9 +62,7 @@ $test->addTestCase(new Doctrine_Filter_TestCase());
$test
->
addTestCase
(
new
Doctrine_ValueHolder_TestCase
());
$test
->
addTestCase
(
new
Doctrine_ValueHolder_TestCase
());
$test
->
addTestCase
(
new
Doctrine_ValidatorTestCase
());
$test
->
addTestCase
(
new
Doctrine_ValidatorTestCase
());
$test
->
addTestCase
(
new
Doctrine_CollectionTestCase
());
$test
->
addTestCase
(
new
Doctrine_QueryTestCase
());
$test
->
addTestCase
(
new
Doctrine_QueryTestCase
());
...
@@ -76,6 +74,7 @@ $test->addTestCase(new Doctrine_SchemaTestCase());
...
@@ -76,6 +74,7 @@ $test->addTestCase(new Doctrine_SchemaTestCase());
$test
->
addTestCase
(
new
Doctrine_ImportTestCase
());
$test
->
addTestCase
(
new
Doctrine_ImportTestCase
());
$test
->
addTestCase
(
new
Doctrine_CollectionTestCase
());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
//$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