我在我的應用程序中遇到了一點障礙,其中定義爲一對多關係的關係返回一個模型對象(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