added mapping check to onetomany. corrected test models.
This commit is contained in:
parent
0b80ec0bfd
commit
73985fe62a
@ -67,6 +67,24 @@ class Doctrine_Association_OneToMany extends Doctrine_Association
|
||||
$this->_isOwningSide = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$mapping = parent::_validateAndCompleteMapping($mapping);
|
||||
// one-side MUST be inverse (must have mappedBy)
|
||||
if ( ! isset($mapping['mappedBy'])) {
|
||||
throw Doctrine_MappingException::oneToManyRequiresMappedBy($mapping['fieldName']);
|
||||
}
|
||||
|
||||
return $mapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether orphaned elements (removed from the collection) should be deleted.
|
||||
*
|
||||
|
@ -47,6 +47,11 @@ class Doctrine_MappingException extends Doctrine_Exception
|
||||
{
|
||||
return new self("No mapping found for field '$fieldName'.");
|
||||
}
|
||||
|
||||
public static function oneToManyRequiresMappedBy($fieldName)
|
||||
{
|
||||
return new self("OneToMany mapping on field '$fieldName' requires the 'mappedBy' attribute.");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -39,6 +39,7 @@ class CmsArticle extends Doctrine_Entity
|
||||
$mapping->mapOneToMany(array(
|
||||
'fieldName' => 'comments',
|
||||
'targetEntity' => 'CmsComment',
|
||||
'mappedBy' => 'article'
|
||||
));
|
||||
|
||||
$mapping->mapManyToOne(array(
|
||||
|
@ -34,5 +34,11 @@ class CmsComment extends Doctrine_Entity
|
||||
'type' => 'integer',
|
||||
'length' => 4
|
||||
));
|
||||
|
||||
$mapping->mapManyToOne(array(
|
||||
'fieldName' => 'article',
|
||||
'targetEntity' => 'CmsArticle',
|
||||
'joinColumns' => array('article_id' => 'id')
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -24,11 +24,8 @@ class ForumBoard extends Doctrine_Entity
|
||||
'fieldName' => 'category_id',
|
||||
'type' => 'integer'
|
||||
));
|
||||
|
||||
/*$mapping->hasOne('ForumCategory as category',
|
||||
array('local' => 'category_id', 'foreign' => 'id'));*/
|
||||
|
||||
$mapping->mapOneToOne(array(
|
||||
$mapping->mapManyToOne(array(
|
||||
'fieldName' => 'category',
|
||||
'targetEntity' => 'ForumCategory',
|
||||
'joinColumns' => array('category_id' => 'id')
|
||||
|
@ -20,12 +20,10 @@ class ForumCategory extends Doctrine_Entity
|
||||
'length' => 255
|
||||
));
|
||||
|
||||
/*$mapping->hasMany('ForumBoard as boards', array(
|
||||
'local' => 'id' , 'foreign' => 'category_id'));*/
|
||||
|
||||
$mapping->mapOneToMany(array(
|
||||
'fieldName' => 'boards',
|
||||
'targetEntity' => 'ForumBoard'
|
||||
'targetEntity' => 'ForumBoard',
|
||||
'mappedBy' => 'category'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user