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
f1adfe7c
Commit
f1adfe7c
authored
Sep 12, 2008
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved association mappings.
parent
81298f96
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
9 additions
and
833 deletions
+9
-833
Association.php
lib/Doctrine/Association.php
+0
-460
ManyToMany.php
lib/Doctrine/Association/ManyToMany.php
+0
-88
OneToMany.php
lib/Doctrine/Association/OneToMany.php
+0
-112
OneToOne.php
lib/Doctrine/Association/OneToOne.php
+0
-164
ClassMetadata.php
lib/Doctrine/ClassMetadata.php
+6
-6
Collection.php
lib/Doctrine/Collection.php
+1
-1
OneToOneMappingTest.php
tests/Orm/Associations/OneToOneMappingTest.php
+2
-2
No files found.
lib/Doctrine/Association.php
deleted
100644 → 0
View file @
81298f96
<?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.org>.
*/
#namespace Doctrine::ORM::Mapping;
/**
* Base class for association mappings.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
* @todo Rename to AssociationMapping.
*/
class
Doctrine_Association
implements
Serializable
{
const
FETCH_MANUAL
=
1
;
const
FETCH_LAZY
=
2
;
const
FETCH_EAGER
=
3
;
/**
* Cascade types enumeration.
*
* @var array
*/
protected
static
$_cascadeTypes
=
array
(
'all'
,
'none'
,
'save'
,
'delete'
,
'refresh'
);
protected
$_cascades
=
array
();
protected
$_isCascadeDelete
;
protected
$_isCascadeSave
;
protected
$_isCascadeRefresh
;
protected
$_customAccessor
;
protected
$_customMutator
;
/**
* The fetch mode used for the association.
*
* @var integer
*/
protected
$_fetchMode
=
self
::
FETCH_MANUAL
;
/**
* Flag that indicates whether the class that defines this mapping is
* the owning side of the association.
*
* @var boolean
*/
protected
$_isOwningSide
=
true
;
/**
* Whether the association is optional (0..X) or not (1..X).
* By default all associations are optional.
*
* @var boolean
*/
protected
$_isOptional
=
true
;
/**
* The name of the source Entity (the Entity that defines this mapping).
*
* @var string
*/
protected
$_sourceEntityName
;
/**
* The name of the target Entity (the Enitity that is the target of the
* association).
*
* @var string
*/
protected
$_targetEntityName
;
/**
* Identifies the field on the source class (the class this AssociationMapping
* belongs to) that represents the association and stores the reference to the
* other entity/entities.
*
* @var string
*/
protected
$_sourceFieldName
;
/**
* Identifies the field on the owning side that controls the mapping for the
* association. This is only set on the inverse side of an association.
*
* @var string
*/
protected
$_mappedByFieldName
;
/**
* Identifies the field on the inverse side of a bidirectional association.
* This is only set on the owning side of an association.
*
* @var string
*/
//protected $_inverseSideFieldName;
/**
* The name of the join table, if any.
*
* @var string
*/
protected
$_joinTable
;
//protected $_mapping = array();
/**
* Constructor.
* Creates a new AssociationMapping.
*
* @param array $mapping The mapping definition.
*/
public
function
__construct
(
array
$mapping
)
{
//$this->_initMappingArray();
//$mapping = $this->_validateAndCompleteMapping($mapping);
//$this->_mapping = array_merge($this->_mapping, $mapping);*/
$this
->
_validateAndCompleteMapping
(
$mapping
);
}
protected
function
_initMappingArray
()
{
$this
->
_mapping
=
array
(
'fieldName'
=>
null
,
'sourceEntity'
=>
null
,
'targetEntity'
=>
null
,
'mappedBy'
=>
null
,
'joinColumns'
=>
null
,
'joinTable'
=>
null
,
'accessor'
=>
null
,
'mutator'
=>
null
,
'optional'
=>
true
,
'cascades'
=>
array
()
);
}
/**
* Validates & completes the mapping. Mapping defaults are applied here.
*
* @param array $mapping
*/
protected
function
_validateAndCompleteMapping
(
array
$mapping
)
{
// Mandatory attributes for both sides
if
(
!
isset
(
$mapping
[
'fieldName'
]))
{
throw
Doctrine_MappingException
::
missingFieldName
();
}
$this
->
_sourceFieldName
=
$mapping
[
'fieldName'
];
if
(
!
isset
(
$mapping
[
'sourceEntity'
]))
{
throw
Doctrine_MappingException
::
missingSourceEntity
(
$mapping
[
'fieldName'
]);
}
$this
->
_sourceEntityName
=
$mapping
[
'sourceEntity'
];
if
(
!
isset
(
$mapping
[
'targetEntity'
]))
{
throw
Doctrine_MappingException
::
missingTargetEntity
(
$mapping
[
'fieldName'
]);
}
$this
->
_targetEntityName
=
$mapping
[
'targetEntity'
];
// Mandatory and optional attributes for either side
if
(
!
isset
(
$mapping
[
'mappedBy'
]))
{
// Optional
if
(
isset
(
$mapping
[
'joinTable'
]))
{
$this
->
_joinTable
=
$mapping
[
'joinTable'
];
}
}
else
{
$this
->
_isOwningSide
=
false
;
$this
->
_mappedByFieldName
=
$mapping
[
'mappedBy'
];
}
// Optional attributes for both sides
if
(
isset
(
$mapping
[
'accessor'
]))
{
$this
->
_customAccessor
=
$mapping
[
'accessor'
];
}
if
(
isset
(
$mapping
[
'mutator'
]))
{
$this
->
_customMutator
=
$mapping
[
'mutator'
];
}
$this
->
_isOptional
=
isset
(
$mapping
[
'optional'
])
?
(
bool
)
$mapping
[
'optional'
]
:
true
;
$this
->
_cascades
=
isset
(
$mapping
[
'cascade'
])
?
(
array
)
$mapping
[
'cascade'
]
:
array
();
}
/**
* Whether the association cascades delete() operations from the source entity
* to the target entity/entities.
*
* @return boolean
*/
public
function
isCascadeDelete
()
{
if
(
is_null
(
$this
->
_isCascadeDelete
))
{
$this
->
_isCascadeDelete
=
in_array
(
'delete'
,
$this
->
_cascades
);
}
return
$this
->
_isCascadeDelete
;
}
/**
* Whether the association cascades save() operations from the source entity
* to the target entity/entities.
*
* @return boolean
*/
public
function
isCascadeSave
()
{
if
(
is_null
(
$this
->
_isCascadeSave
))
{
$this
->
_isCascadeSave
=
in_array
(
'save'
,
$this
->
_cascades
);
}
return
$this
->
_isCascadeSave
;
}
/**
* Whether the association cascades refresh() operations from the source entity
* to the target entity/entities.
*
* @return boolean
*/
public
function
isCascadeRefresh
()
{
if
(
is_null
(
$this
->
_isCascadeRefresh
))
{
$this
->
_isCascadeRefresh
=
in_array
(
'refresh'
,
$this
->
_cascades
);
}
return
$this
->
_isCascadeRefresh
;
}
/**
* Whether the target entity/entities of the association are eagerly fetched.
*
* @return boolean
*/
public
function
isEagerlyFetched
()
{
return
$this
->
_fetchMode
==
self
::
FETCH_EAGER
;
}
/**
* Whether the target entity/entities of the association are lazily fetched.
*
* @return boolean
*/
public
function
isLazilyFetched
()
{
return
$this
->
_fetchMode
==
self
::
FETCH_LAZY
;
}
/**
* Whether the target entity/entities of the association are manually fetched.
*
* @return boolean
*/
public
function
isManuallyFetched
()
{
return
$this
->
_fetchMode
==
self
::
FETCH_MANUAL
;
}
/**
* Whether the source entity of this association represents the owning side.
*
* @return boolean
*/
public
function
isOwningSide
()
{
return
$this
->
_isOwningSide
;
}
/**
* Whether the source entity of this association represents the inverse side.
*
* @return boolean
*/
public
function
isInverseSide
()
{
return
!
$this
->
_isOwningSide
;
}
/**
* Whether the association is optional (0..X), or not (1..X).
*
* @return boolean TRUE if the association is optional, FALSE otherwise.
*/
public
function
isOptional
()
{
return
$this
->
_isOptional
;
}
/**
* Gets the name of the source entity class.
*
* @return string
*/
public
function
getSourceEntityName
()
{
return
$this
->
_sourceEntityName
;
}
/**
* Gets the name of the target entity class.
*
* @return string
*/
public
function
getTargetEntityName
()
{
return
$this
->
_targetEntityName
;
}
/**
* Gets the name of the join table.
*
* @return string
*/
public
function
getJoinTable
()
{
return
$this
->
_joinTable
;
}
/**
* Get the name of the field the association is mapped into.
*
* @return string
*/
public
function
getSourceFieldName
()
{
return
$this
->
_sourceFieldName
;
}
/**
* Gets the field name of the owning side in a bi-directional association.
*
* @return string
*/
public
function
getMappedByFieldName
()
{
return
$this
->
_mappedByFieldName
;
}
/*public function getInverseSideFieldName()
{
return $this->_inverseSideFieldName;
}*/
/**
* Marks the association as bidirectional, specifying the field name of
* the inverse side.
* This is called on the owning side, when an inverse side is discovered.
* This does only make sense to call on the owning side.
*
* @param string $inverseSideFieldName
*/
/*public function setBidirectional($inverseSideFieldName)
{
if ( ! $this->_isOwningSide) {
return; //TODO: exception?
}
$this->_inverseSideFieldName = $inverseSideFieldName;
}*/
/**
* Whether the association is bidirectional.
*
* @return boolean
*/
/*public function isBidirectional()
{
return $this->_mappedByFieldName || $this->_inverseSideFieldName;
}*/
/**
* Whether the source field of the association has a custom accessor.
*
* @return boolean TRUE if the source field of the association has a custom accessor,
* FALSE otherwise.
*/
public
function
hasCustomAccessor
()
{
return
isset
(
$this
->
_customAccessor
);
}
/**
* Gets the name of the custom accessor method of the source field.
*
* @return string The name of the accessor method or NULL.
*/
public
function
getCustomAccessor
()
{
return
$this
->
_customAccessor
;
}
/**
* Whether the source field of the association has a custom mutator.
*
* @return boolean TRUE if the source field of the association has a custom mutator,
* FALSE otherwise.
*/
public
function
hasCustomMutator
()
{
return
isset
(
$this
->
_customMutator
);
}
/**
* Gets the name of the custom mutator method of the source field.
*
* @return string The name of the mutator method or NULL.
*/
public
function
getCustomMutator
()
{
return
$this
->
_customMutator
;
}
public
function
isOneToOne
()
{
return
false
;
}
public
function
isOneToMany
()
{
return
false
;
}
public
function
isManyToMany
()
{
return
false
;
}
/* Serializable implementation */
public
function
serialize
()
{
return
""
;
}
public
function
unserialize
(
$serialized
)
{
return
true
;
}
}
?>
\ No newline at end of file
lib/Doctrine/Association/ManyToMany.php
deleted
100644 → 0
View file @
81298f96
<?php
#namespace Doctrine::ORM::Mapping;
/**
* A many-to-many mapping describes the mapping between two collections of
* entities.
*
* @since 2.0
* @todo Rename to ManyToManyMapping
*/
class
Doctrine_Association_ManyToMany
extends
Doctrine_Association
{
/**
* The name of the association class (if an association class is used).
*
* @var string
*/
private
$_associationClass
;
/** The field in the source table that corresponds to the key in the relation table */
protected
$_sourceKeyColumns
;
/** The field in the target table that corresponds to the key in the relation table */
protected
$_targetKeyColumns
;
/** The field in the intermediate table that corresponds to the key in the source table */
protected
$_sourceRelationKeyColumns
;
/** The field in the intermediate table that corresponds to the key in the target table */
protected
$_targetRelationKeyColumns
;
/**
* Constructor.
* Creates a new ManyToManyMapping.
*
* @param array $mapping The mapping info.
*/
public
function
__construct
(
array
$mapping
)
{
parent
::
__construct
(
$mapping
);
}
/**
* Validates and completes the mapping.
*
* @param array $mapping
* @override
*/
protected
function
_validateAndCompleteMapping
(
array
$mapping
)
{
parent
::
_validateAndCompleteMapping
(
$mapping
);
if
(
$this
->
isOwningSide
())
{
// many-many owning MUST have a join table
if
(
!
isset
(
$mapping
[
'joinTable'
]))
{
throw
Doctrine_MappingException
::
joinTableRequired
(
$mapping
[
'fieldName'
]);
}
// optional attributes for many-many owning side
$this
->
_associationClass
=
isset
(
$mapping
[
'associationClass'
])
?
$mapping
[
'associationClass'
]
:
null
;
}
}
/**
* Whether the mapping uses an association class for the intermediary
* table.
*
* @return boolean
*/
public
function
usesAssociationClass
()
{
return
$this
->
_associationClass
!==
null
;
}
/**
* Gets the name of the association class.
*
* @return string
*/
public
function
getAssociationClassName
()
{
return
$this
->
_associationClass
;
}
}
?>
\ No newline at end of file
lib/Doctrine/Association/OneToMany.php
deleted
100644 → 0
View file @
81298f96
<?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.org>.
*/
#namespace Doctrine::ORM::Mapping;
/**
* Represents a one-to-many mapping.
*
* NOTE: One-to-many mappings can currently not be uni-directional (one -> many).
* They must either be bidirectional (one <-> many) or unidirectional (many -> one).
* In other words, the many-side MUST be the owning side and the one-side MUST be
* the inverse side.
*
* @author Roman Borschel <roman@code-factory.org>
* @since 2.0
* @todo Rename to OneToManyMapping
*/
class
Doctrine_Association_OneToMany
extends
Doctrine_Association
{
/** The target foreign key columns that reference the sourceKeyColumns. */
/* NOTE: Currently not used because uni-directional one-many not supported atm. */
//protected $_targetForeignKeyColumns;
/** The (typically primary) source key columns that are referenced by the targetForeignKeyColumns. */
/* NOTE: Currently not used because uni-directional one-many not supported atm. */
//protected $_sourceKeyColumns;
/** This maps the target foreign key columns to the corresponding (primary) source key columns. */
/* NOTE: Currently not used because uni-directional one-many not supported atm. */
//protected $_targetForeignKeysToSourceKeys;
/** This maps the (primary) source key columns to the corresponding target foreign key columns. */
/* NOTE: Currently not used because uni-directional one-many not supported atm. */
//protected $_sourceKeysToTargetForeignKeys;
/** Whether to delete orphaned elements (removed from the collection) */
protected
$_deleteOrphans
=
false
;
/**
* Constructor.
* Creates a new OneToManyMapping.
*
* @param array $mapping The mapping info.
*/
public
function
__construct
(
array
$mapping
)
{
parent
::
__construct
(
$mapping
);
}
/**
* Validates and completed the mapping.
*
* @param array $mapping The mapping to validate and complete.
* @return array The validated and completed mapping.
* @override
*/
protected
function
_validateAndCompleteMapping
(
array
$mapping
)
{
parent
::
_validateAndCompleteMapping
(
$mapping
);
// one-side MUST be inverse (must have mappedBy)
if
(
!
isset
(
$mapping
[
'mappedBy'
]))
{
throw
Doctrine_MappingException
::
oneToManyRequiresMappedBy
(
$mapping
[
'fieldName'
]);
}
$this
->
_deleteOrphans
=
isset
(
$mapping
[
'deleteOrphans'
])
?
(
bool
)
$mapping
[
'deleteOrphans'
]
:
false
;
}
/**
* Whether orphaned elements (removed from the collection) should be deleted.
*
* @return boolean TRUE if orphaned elements should be deleted, FALSE otherwise.
*/
public
function
shouldDeleteOrphans
()
{
return
$this
->
_deleteOrphans
;
}
/**
* Whether the association is one-to-many.
*
* @return boolean TRUE if the association is one-to-many, FALSE otherwise.
* @override
*/
public
function
isOneToMany
()
{
return
true
;
}
}
?>
\ No newline at end of file
lib/Doctrine/Association/OneToOne.php
deleted
100644 → 0
View file @
81298f96
<?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.org>.
*/
#namespace Doctrine::ORM::Mappings;
#use Doctrine::ORM::Entity;
/**
* A one-to-one mapping describes a uni-directional mapping from one entity
* to another entity.
*
* @since 2.0
* @author Roman Borschel <roman@code-factory.org>
* @todo Rename to OneToOneMapping
*/
class
Doctrine_Association_OneToOne
extends
Doctrine_Association
{
/**
* Maps the source foreign/primary key columns to the target primary/foreign key columns.
* i.e. source.id (pk) => target.user_id (fk).
* Reverse mapping of _targetToSourceKeyColumns.
*/
protected
$_sourceToTargetKeyColumns
=
array
();
/**
* Maps the target primary/foreign key columns to the source foreign/primary key columns.
* i.e. target.user_id (fk) => source.id (pk).
* Reverse mapping of _sourceToTargetKeyColumns.
*/
protected
$_targetToSourceKeyColumns
=
array
();
/**
* Whether to delete orphaned elements (when nulled out, i.e. $foo->other = null)
*
* @var boolean
*/
protected
$_deleteOrphans
=
false
;
/**
* Constructor.
* Creates a new OneToOneMapping.
*
* @param array $mapping The mapping info.
*/
public
function
__construct
(
array
$mapping
)
{
parent
::
__construct
(
$mapping
);
}
protected
function
_initMappingArray
()
{
parent
::
_initMappingArray
();
$this
->
_mapping
[
'deleteOrphans'
]
=
false
;
}
/**
* Validates & completes the mapping. Mapping defaults are applied here.
*
* @param array $mapping The mapping to validate & complete.
* @return array The validated & completed mapping.
* @override
*/
protected
function
_validateAndCompleteMapping
(
array
$mapping
)
{
parent
::
_validateAndCompleteMapping
(
$mapping
);
if
(
$this
->
isOwningSide
())
{
if
(
!
isset
(
$mapping
[
'joinColumns'
]))
{
throw
Doctrine_MappingException
::
invalidMapping
(
$this
->
_sourceFieldName
);
}
$this
->
_sourceToTargetKeyColumns
=
$mapping
[
'joinColumns'
];
$this
->
_targetToSourceKeyColumns
=
array_flip
(
$this
->
_sourceToTargetKeyColumns
);
}
$this
->
_deleteOrphans
=
isset
(
$mapping
[
'deleteOrphans'
])
?
(
bool
)
$mapping
[
'deleteOrphans'
]
:
false
;
return
$mapping
;
}
/**
* Gets the source-to-target key column mapping.
*
* @return unknown
*/
public
function
getSourceToTargetKeyColumns
()
{
return
$this
->
_sourceToTargetKeyColumns
;
}
/**
* Gets the target-to-source key column mapping.
*
* @return unknown
*/
public
function
getTargetToSourceKeyColumns
()
{
return
$this
->
_targetToSourceKeyColumns
;
}
/**
* Whether the association is one-to-one.
*
* @return boolean
* @override
*/
public
function
isOneToOne
()
{
return
true
;
}
/**
* Lazy-loads the associated entity for a given entity.
*
* @param Doctrine::ORM::Entity $entity
* @return void
*/
public
function
lazyLoadFor
(
Doctrine_Entity
$entity
)
{
if
(
$entity
->
getClassName
()
!=
$this
->
_sourceClass
->
getClassName
())
{
//error?
}
$dql
=
'SELECT t.* FROM '
.
$this
->
_targetClass
->
getClassName
()
.
' t WHERE '
;
$params
=
array
();
foreach
(
$this
->
_sourceToTargetKeyFields
as
$sourceKeyField
=>
$targetKeyField
)
{
if
(
$params
)
{
$dql
.=
" AND "
;
}
$dql
.=
"t.
$targetKeyField
= ?"
;
$params
[]
=
$entity
->
_rawGetField
(
$sourceKeyField
);
}
$otherEntity
=
$this
->
_targetClass
->
getEntityManager
()
->
query
(
$dql
,
$params
)
->
getFirst
();
if
(
!
$otherEntity
)
{
$otherEntity
=
Doctrine_Null
::
$INSTANCE
;
}
$entity
->
_internalSetReference
(
$this
->
_sourceFieldName
,
$otherEntity
);
}
}
?>
\ No newline at end of file
lib/Doctrine/ClassMetadata.php
View file @
f1adfe7c
...
@@ -1552,7 +1552,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
...
@@ -1552,7 +1552,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
* @param Doctrine_Association $assoc
* @param Doctrine_Association $assoc
* @param unknown_type $fieldName
* @param unknown_type $fieldName
*/
*/
private
function
_registerCustomAssociationAccessors
(
Doctrine_
Association
$assoc
,
$fieldName
)
private
function
_registerCustomAssociationAccessors
(
Doctrine_
ORM_Mapping_AssociationMapping
$assoc
,
$fieldName
)
{
{
if
(
$acc
=
$assoc
->
getCustomAccessor
())
{
if
(
$acc
=
$assoc
->
getCustomAccessor
())
{
$this
->
_customAssociationAccessors
[
$fieldName
]
=
$acc
;
$this
->
_customAssociationAccessors
[
$fieldName
]
=
$acc
;
...
@@ -1570,7 +1570,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
...
@@ -1570,7 +1570,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
public
function
mapOneToOne
(
array
$mapping
)
public
function
mapOneToOne
(
array
$mapping
)
{
{
$mapping
=
$this
->
_completeAssociationMapping
(
$mapping
);
$mapping
=
$this
->
_completeAssociationMapping
(
$mapping
);
$oneToOneMapping
=
new
Doctrine_
Association_OneToOne
(
$mapping
);
$oneToOneMapping
=
new
Doctrine_
ORM_Mapping_OneToOneMapping
(
$mapping
);
$this
->
_storeAssociationMapping
(
$oneToOneMapping
);
$this
->
_storeAssociationMapping
(
$oneToOneMapping
);
/*if ($oneToOneMapping->isInverseSide()) {
/*if ($oneToOneMapping->isInverseSide()) {
...
@@ -1583,7 +1583,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
...
@@ -1583,7 +1583,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
}*/
}*/
}
}
private
function
_registerMappingIfInverse
(
Doctrine_
Association
$assoc
)
private
function
_registerMappingIfInverse
(
Doctrine_
ORM_Mapping_AssociationMapping
$assoc
)
{
{
if
(
$assoc
->
isInverseSide
())
{
if
(
$assoc
->
isInverseSide
())
{
$this
->
_inverseMappings
[
$assoc
->
getMappedByFieldName
()]
=
$assoc
;
$this
->
_inverseMappings
[
$assoc
->
getMappedByFieldName
()]
=
$assoc
;
...
@@ -1598,7 +1598,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
...
@@ -1598,7 +1598,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
public
function
mapOneToMany
(
array
$mapping
)
public
function
mapOneToMany
(
array
$mapping
)
{
{
$mapping
=
$this
->
_completeAssociationMapping
(
$mapping
);
$mapping
=
$this
->
_completeAssociationMapping
(
$mapping
);
$oneToManyMapping
=
new
Doctrine_
Association_OneToMany
(
$mapping
);
$oneToManyMapping
=
new
Doctrine_
ORM_Mapping_OneToManyMapping
(
$mapping
);
$this
->
_storeAssociationMapping
(
$oneToManyMapping
);
$this
->
_storeAssociationMapping
(
$oneToManyMapping
);
}
}
...
@@ -1621,7 +1621,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
...
@@ -1621,7 +1621,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
public
function
mapManyToMany
(
array
$mapping
)
public
function
mapManyToMany
(
array
$mapping
)
{
{
$mapping
=
$this
->
_completeAssociationMapping
(
$mapping
);
$mapping
=
$this
->
_completeAssociationMapping
(
$mapping
);
$manyToManyMapping
=
new
Doctrine_
Association
_ManyToManyMapping
(
$mapping
);
$manyToManyMapping
=
new
Doctrine_
ORM_Mapping
_ManyToManyMapping
(
$mapping
);
$this
->
_storeAssociationMapping
(
$manyToManyMapping
);
$this
->
_storeAssociationMapping
(
$manyToManyMapping
);
}
}
...
@@ -1630,7 +1630,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
...
@@ -1630,7 +1630,7 @@ class Doctrine_ClassMetadata implements Doctrine_Configurable, Serializable
*
*
* @param Doctrine_Association $assocMapping
* @param Doctrine_Association $assocMapping
*/
*/
private
function
_storeAssociationMapping
(
Doctrine_
Association
$assocMapping
)
private
function
_storeAssociationMapping
(
Doctrine_
ORM_Mapping_AssociationMapping
$assocMapping
)
{
{
$sourceFieldName
=
$assocMapping
->
getSourceFieldName
();
$sourceFieldName
=
$assocMapping
->
getSourceFieldName
();
if
(
isset
(
$this
->
_associationMappings
[
$sourceFieldName
]))
{
if
(
isset
(
$this
->
_associationMappings
[
$sourceFieldName
]))
{
...
...
lib/Doctrine/Collection.php
View file @
f1adfe7c
...
@@ -229,7 +229,7 @@ class Doctrine_Collection implements Countable, IteratorAggregate, Serializable,
...
@@ -229,7 +229,7 @@ class Doctrine_Collection implements Countable, IteratorAggregate, Serializable,
*
*
* @return void
* @return void
*/
*/
public
function
_setOwner
(
Doctrine_Entity
$entity
,
Doctrine_
Association
$relation
)
public
function
_setOwner
(
Doctrine_Entity
$entity
,
Doctrine_
ORM_Mapping_AssociationMapping
$relation
)
{
{
$this
->
_owner
=
$entity
;
$this
->
_owner
=
$entity
;
$this
->
_association
=
$relation
;
$this
->
_association
=
$relation
;
...
...
tests/Orm/Associations/OneToOneMappingTest.php
View file @
f1adfe7c
...
@@ -12,7 +12,7 @@ class Orm_Associations_OneToOneMappingTest extends Doctrine_OrmTestCase
...
@@ -12,7 +12,7 @@ class Orm_Associations_OneToOneMappingTest extends Doctrine_OrmTestCase
'sourceEntity'
=>
'Person'
,
// This is normally filled by ClassMetadata
'sourceEntity'
=>
'Person'
,
// This is normally filled by ClassMetadata
);
);
$oneToOneMapping
=
new
Doctrine_
Association_OneToOne
(
$owningSideMapping
);
$oneToOneMapping
=
new
Doctrine_
ORM_Mapping_OneToOneMapping
(
$owningSideMapping
);
$this
->
assertEquals
(
array
(
'address_id'
=>
'id'
),
$oneToOneMapping
->
getSourceToTargetKeyColumns
());
$this
->
assertEquals
(
array
(
'address_id'
=>
'id'
),
$oneToOneMapping
->
getSourceToTargetKeyColumns
());
$this
->
assertEquals
(
array
(
'id'
=>
'address_id'
),
$oneToOneMapping
->
getTargetToSourceKeyColumns
());
$this
->
assertEquals
(
array
(
'id'
=>
'address_id'
),
$oneToOneMapping
->
getTargetToSourceKeyColumns
());
...
@@ -29,7 +29,7 @@ class Orm_Associations_OneToOneMappingTest extends Doctrine_OrmTestCase
...
@@ -29,7 +29,7 @@ class Orm_Associations_OneToOneMappingTest extends Doctrine_OrmTestCase
'mappedBy'
=>
'address'
'mappedBy'
=>
'address'
);
);
$oneToOneMapping
=
new
Doctrine_
Association_OneToOne
(
$inverseSideMapping
);
$oneToOneMapping
=
new
Doctrine_
ORM_Mapping_OneToOneMapping
(
$inverseSideMapping
);
$this
->
assertEquals
(
'address'
,
$oneToOneMapping
->
getMappedByFieldName
());
$this
->
assertEquals
(
'address'
,
$oneToOneMapping
->
getMappedByFieldName
());
$this
->
assertEquals
(
'Address'
,
$oneToOneMapping
->
getSourceEntityName
());
$this
->
assertEquals
(
'Address'
,
$oneToOneMapping
->
getSourceEntityName
());
$this
->
assertEquals
(
'Person'
,
$oneToOneMapping
->
getTargetEntityName
());
$this
->
assertEquals
(
'Person'
,
$oneToOneMapping
->
getTargetEntityName
());
...
...
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