1
0
mirror of synced 2024-12-13 06:46:03 +03:00

added mapping check to onetomany. corrected test models.

This commit is contained in:
romanb 2008-08-22 09:37:03 +00:00
parent 0b80ec0bfd
commit 73985fe62a
6 changed files with 33 additions and 8 deletions

View File

@ -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.
*

View File

@ -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.");
}
}
?>

View File

@ -39,6 +39,7 @@ class CmsArticle extends Doctrine_Entity
$mapping->mapOneToMany(array(
'fieldName' => 'comments',
'targetEntity' => 'CmsComment',
'mappedBy' => 'article'
));
$mapping->mapManyToOne(array(

View File

@ -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')
));
}
}

View File

@ -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')

View File

@ -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'
));
}
}