I ran into some problem in my application where relationships defined as a one-to-many relationship return a model object (instance of Doctrine_Record) instead of Doctrine_Collection when I try to access it as $model->RelatedComponent[] = $child1. This, of course, gives an exception:
Doctrine_Exception: add is not supported for AuditLogProperty
# 0 path \ library \ Doctrine \ Access.php (131): Doctrine_Access-> Add (Object (AuditLogProperty))
# 1 path \ application \ models \ Article.php (58): Doctrine_Access-> offsetSet (NULL, Object (AuditLogProperty))
# 2 path \ library \ Doctrine \ Record.php (354): Article-> postInsert (Object (Doctrine_Event))
# 3 path \ library \ Doctrine \ Connection \ UnitOfWork.php (576): Doctrine_Record-> invokeSaveHooks ('post', 'insert', Object (Doctrine_Event))
# 4 path \ library \ Doctrine \ Connection \ UnitOfWork.php (81): Doctrine_Connection_UnitOfWork-> paste (Object (article))
# 5 path \ library \ Doctrine \ Record.php (1718): Doctrine_Connection_UnitOfWork-> saveGraph (Object (article))
# 6 path \ application \ modules \ my-page \ controllers \ ArticleController.php (26): Doctrine_Record-> Save ()
# 7 path \ library \ Zend \ Controller \ Action.php (513): MyPage_ArticleController-> createAction ()
# 8 path \ library \ Zend \ Controller \ Dispatcher \ Standard.php (289): Zend_Controller_Action-> submit ('createAction')
# 9 path\library\Zend\Controller\Front.php(946): Zend_Controller_Dispatcher_Standard- > (Object (Zend_Controller_Request_Http), (Zend_Controller_Response_Http))
# 10 path\library\Zend\Application\Bootstrap\Bootstrap.php(77): Zend_Controller_Front- > ()
# 11 path\library\Zend\Application.php(358): Zend_Application_Bootstrap_Bootstrap- > Run()
# 12 path\public\index.php(11): Zend_Application- > Run()
# 13 {main}
yaml- ():
AuditLogEntry:
tableName: audit_log_entries
actAs:
Timestampable:
updated: {disabled: true}
columns:
user_id: {type: integer(8), unsigned: true, primary: true}
id: {type: integer(8), unsigned: true, primary: true, autoincrement: true}
type: {type: string(255), notnull: true}
mode: {type: string(16)}
article_id: {type: integer(8), unsigned: true}
comment_id: {type: integer(8), unsigned: true}
question_id: {type: integer(8), unsigned: true}
answer_id: {type: integer(8), unsigned: true}
message_id: {type: integer(8), unsigned: true}
indexes:
# Must index autoincrementing id-column since it a compound primary key and
# the auto-incrementing column is not the first column and we use InnoDB.
id: {fields: [id]}
type: {fields: [type, mode]}
relations:
User:
local: user_id
foreign: user_id
foreignAlias: AuditLogs
type: one
onDelete: CASCADE
onUpdate: CASCADE
:
AuditLogProperty:
tableName: audit_log_properties
columns:
auditlog_id: {type: integer(8), unsigned: true, primary: true}
prop_id: {type: integer(2), unsigned: true, primary: true, default: 1}
name: {type: string(255), notnull: true}
value: {type: string(1024)}
relations:
AuditLogEntry:
local: auditlog_id
foreign: id
type: one
foreignType: many
foreignAlias: Properties
onDelete: CASCADE
onUpdate: CASCADE
, , :
/**
* @property integer $user_id
* @property integer $id
* @property string $type
* @property string $mode
* @property integer $article_id
* @property integer $comment_id
* @property integer $question_id
* @property integer $answer_id
* @property integer $message_id
* @property integer $news_comment_id
* @property User $User
* @property Doctrine_Collection $Properties
* @property Doctrine_Collection $Notifications
*/
abstract class BaseAuditLogEntry extends Doctrine_Record
/**
* @property integer $auditlog_id
* @property integer $prop_id
* @property string $name
* @property string $value
* @property AuditLogEntry $AuditLogEntry
*/
abstract class BaseAuditLogProperty extends Doctrine_Record
, , , :
$auditLog = new AuditLogEntry();
$prop1 = new AuditLogProperty();
$prop1->name = 'title';
$prop1->value = $this->Content->title;
$prop2 = new AuditLogProperty();
$prop2->name = 'length';
$prop2->value = count($this->Content->plainText);
$auditLog->Properties[] = $prop1;
$auditLog->Properties[] = $prop2;
$auditLog->save();
:
var_dump(get_class($auditLog->Properties));
, Properties AuditLogProperty Doctrine_Collection.
1.2.3 .