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
1a0179bd
Commit
1a0179bd
authored
Sep 27, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #128
Ticket: 128
parent
7b84d155
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
30 deletions
+37
-30
Self.php
lib/Doctrine/Association/Self.php
+34
-0
Record.php
lib/Doctrine/Record.php
+3
-30
No files found.
lib/Doctrine/Association/Self.php
View file @
1a0179bd
...
...
@@ -52,5 +52,39 @@ class Doctrine_Association_Self extends Doctrine_Association {
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/Record.php
View file @
1a0179bd
...
...
@@ -594,6 +594,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* @param $name name of the property
* @return mixed
*/
public
function
rawGet
(
$name
)
{
if
(
!
isset
(
$this
->
data
[
$name
]))
throw
new
InvalidKeyException
();
...
...
@@ -603,6 +604,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
return
$this
->
data
[
$name
];
}
/**
* load
* loads all the unitialized properties from the database
...
...
@@ -1299,36 +1301,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$coll
=
$graph
->
query
(
$query
,
array
(
$id
));
$coll
->
setReference
(
$this
,
$fk
);
}
elseif
(
$fk
instanceof
Doctrine_Association_Self
)
{
$id
=
$this
->
getIncremented
();
$q
=
new
Doctrine_RawSql
();
$assocTable
=
$fk
->
getAssociationFactory
()
->
getTableName
();
$tableName
=
$this
->
getTable
()
->
getTableName
();
$identifier
=
$this
->
getTable
()
->
getIdentifier
();
$sub
=
"SELECT "
.
$fk
->
getForeign
()
.
" FROM "
.
$assocTable
.
" WHERE "
.
$fk
->
getLocal
()
.
" = ?"
;
$sub2
=
"SELECT "
.
$fk
->
getLocal
()
.
" FROM "
.
$assocTable
.
" WHERE "
.
$fk
->
getForeign
()
.
" = ?"
;
$q
->
select
(
'{'
.
$tableName
.
'.*}, {'
.
$assocTable
.
'.*}'
)
->
from
(
$tableName
.
' INNER JOIN '
.
$assocTable
.
' ON '
.
$tableName
.
'.'
.
$identifier
.
' = '
.
$assocTable
.
'.'
.
$fk
->
getLocal
()
.
' OR '
.
$tableName
.
'.'
.
$identifier
.
' = '
.
$assocTable
.
'.'
.
$fk
->
getForeign
()
)
->
where
(
$tableName
.
'.'
.
$identifier
.
' IN ('
.
$sub
.
') OR '
.
$tableName
.
'.'
.
$identifier
.
' IN ('
.
$sub2
.
')'
);
$q
->
addComponent
(
$tableName
,
$this
->
table
->
getComponentName
());
$q
->
addComponent
(
$assocTable
,
$this
->
table
->
getComponentName
()
.
'.'
.
$fk
->
getAssociationFactory
()
->
getComponentName
());
$coll
=
$q
->
execute
(
array
(
$id
,
$id
));
$coll
=
$fk
->
fetchRelatedFor
(
$this
);
}
elseif
(
$fk
instanceof
Doctrine_Association
)
{
$id
=
$this
->
getIncremented
();
$coll
=
$graph
->
query
(
$query
,
array
(
$id
));
...
...
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