我在我的应用程序中遇到了一点障碍,其中定义为一对多关系的关系返回一个模型对象(Doctrine_Record的实例)当我尝试以$model->RelatedComponent[] = $child1
的身份访问它时,而不是Doctrine_Collection。此,当然,产生一个异常,像这样:学说一对多关系返回一个Doctrine_Record而不是Doctrine_Collection
Doctrine_Exception:添加不支持AuditLogProperty
#0 路径 \库\学说\ Access.php(131): Doctrine_Access->添加(对象(AuditLogProperty))
#1 路径 \应用\模型\ Article.php(58): Doctrine_Access-> offsetSet(NULL, 对象(AuditLogProperty))
#2 路径 \库\学说\ Record.php(354): 物品─> postInsert(对象(Doctrine_Event))
#3 路径 \库\学说\连接\ UnitOfWork.php (576): Doctrine_Record-> invokeSaveHooks( '后', '插入',对象(Doctrine_Event))
#4 路径 \库\学说\连接\ UnitOfWork.php(81): Doctrine_Connection_UnitOfWork- > insert(Object(Article))
#5 路径 \库\学说\ Record.php(1718): Doctrine_Connection_UnitOfWork-> saveGraph(对象(第))
#6 路径 \应用\模块\我的页面\控制器\ ArticleController.php(26): Doctrine_Record->保存()
#7 路径 \库\ Zend的\控制器\ action.php的(513): MyPage_ArticleController-> createAction()
# 8 路径 \库\ Zend的\控制器\分派器\ Standard.php(289): Zend_Controller_Action->调度( 'createAction')
#9 路径 \库\ Zend的\控制器\ Front.php(946 ): Zend_Controller_Dispatcher_Standard->调度(对象(的Zend_Controller_Request_Http) 对象(Zend_Controller_Response_Http))
#10 路径 \库\ Zend的\应用程序\引导\ bootstrap.php中(77): Zend_Controller_Front->调度( )
#11 路径 \库\ Zend的\ Application.php(358): Zend_Application_Bootstrap_Bootstrap->的run()
#12 路径 \公共\索引。PHP(11): Zend_Application-> run()的
#{13}主要
这就是我的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'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
然后我们有相关的模式:
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
。
我使用Doctrine的版本1.2.3。
- 任何人都可以发现什么是错的?
- 问题是我使用复合主键的方式主义不同意?
- 如何解决它的任何想法?
我遇到同样的问题。问题存在于Doctrine 1.2.X(我测试过以前的版本)。 – 2010-10-01 17:00:56
我已经提交了一个关于doctrine-project的错误:http://www.doctrine-project.org/jira/browse/DC-875 – PatrikAkerstrand 2010-10-01 17:35:02