I have encounter a little of the snag during my application in which a relationship understood to be a 1-to-many relationship returns one object (demonstration of Doctrine_Record) rather than a Doctrine_Collection after i attempt to can get on as $model->RelatedComponent[] = $child1. This, obviously, yields the best like so:

Doctrine_Exception: Add isn't supported for AuditLogProperty

# pathlibraryDoctrineAccess.php(131): Doctrine_Access->add(Object(AuditLogProperty))

#1 pathapplicationmodelsArticle.php(58): Doctrine_Access->offsetSet(NULL, Object(AuditLogProperty))

#2 pathlibraryDoctrineRecord.php(354): Article->postInsert(Object(Doctrine_Event))

#3 pathlibraryDoctrineConnectionUnitOfWork.php(576): Doctrine_Record->invokeSaveHooks('post', 'insert', Object(Doctrine_Event))

#4 pathlibraryDoctrineConnectionUnitOfWork.php(81): Doctrine_Connection_UnitOfWork->insert(Object(Article))

#5 pathlibraryDoctrineRecord.php(1718): Doctrine_Connection_UnitOfWork->saveGraph(Object(Article))

#6 pathapplicationmodulesmy-pagecontrollersArticleController.php(26): Doctrine_Record->save()

#7 pathlibraryZendControllerAction.php(513): MyPage_ArticleController->createAction()

#8 pathlibraryZendControllerDispatcherStandard.php(289): Zend_Controller_Action->dispatch('createAction')

#9 pathlibraryZendControllerFront.php(946): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))

#10 pathlibraryZendApplicationBootstrapBootstrap.php(77): Zend_Controller_Front->dispatch()

#11 pathlibraryZendApplication.php(358): Zend_Application_Bootstrap_Bootstrap->run()

#12 pathpublicindex.php(11): Zend_Application->run()

#13 primary

This is exactly what my yaml-schema appears like (excerpt):

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's 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

Therefore we possess the related model:

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

Now, when we consider the produced class-files, it appears fine:

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

However, after i later consider adding qualities I recieve the exception published at first from the question:

$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();

Basically perform the following:

var_dump(get_class($auditLog->Properties));

I recieve that Properties is of type AuditLogProperty, rather than Doctrine_Collection.

I personally use version 1.2.3 of Doctrine.

  • Can anybody place what's wrong?
  • May be the problem which i use compound primary secrets in ways Doctrine does not agree to?
  • Any ideas of methods to resolve it?