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;
|
$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.
|
* 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'.");
|
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(
|
$mapping->mapOneToMany(array(
|
||||||
'fieldName' => 'comments',
|
'fieldName' => 'comments',
|
||||||
'targetEntity' => 'CmsComment',
|
'targetEntity' => 'CmsComment',
|
||||||
|
'mappedBy' => 'article'
|
||||||
));
|
));
|
||||||
|
|
||||||
$mapping->mapManyToOne(array(
|
$mapping->mapManyToOne(array(
|
||||||
|
@ -34,5 +34,11 @@ class CmsComment extends Doctrine_Entity
|
|||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
'length' => 4
|
'length' => 4
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$mapping->mapManyToOne(array(
|
||||||
|
'fieldName' => 'article',
|
||||||
|
'targetEntity' => 'CmsArticle',
|
||||||
|
'joinColumns' => array('article_id' => 'id')
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,7 @@ class ForumBoard extends Doctrine_Entity
|
|||||||
'type' => 'integer'
|
'type' => 'integer'
|
||||||
));
|
));
|
||||||
|
|
||||||
/*$mapping->hasOne('ForumCategory as category',
|
$mapping->mapManyToOne(array(
|
||||||
array('local' => 'category_id', 'foreign' => 'id'));*/
|
|
||||||
|
|
||||||
$mapping->mapOneToOne(array(
|
|
||||||
'fieldName' => 'category',
|
'fieldName' => 'category',
|
||||||
'targetEntity' => 'ForumCategory',
|
'targetEntity' => 'ForumCategory',
|
||||||
'joinColumns' => array('category_id' => 'id')
|
'joinColumns' => array('category_id' => 'id')
|
||||||
|
@ -20,12 +20,10 @@ class ForumCategory extends Doctrine_Entity
|
|||||||
'length' => 255
|
'length' => 255
|
||||||
));
|
));
|
||||||
|
|
||||||
/*$mapping->hasMany('ForumBoard as boards', array(
|
|
||||||
'local' => 'id' , 'foreign' => 'category_id'));*/
|
|
||||||
|
|
||||||
$mapping->mapOneToMany(array(
|
$mapping->mapOneToMany(array(
|
||||||
'fieldName' => 'boards',
|
'fieldName' => 'boards',
|
||||||
'targetEntity' => 'ForumBoard'
|
'targetEntity' => 'ForumBoard',
|
||||||
|
'mappedBy' => 'category'
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user