2012-10-30 48 views
0

我有一個問題,使用命令生成我的表:類必須是一個子類Doctrine_Record誤差對PHP symfony的學說:插入-SQL

php symfony doctrine:insert-sql 

它返回我下面的錯誤:

>> doctrine creating tables 


    Class "Complaint" must be a child class of Doctrine_Record 


PHP Fatal error: Call to a member function evictAll() on a non-object in D:\Internet\PHP\ijzerleeuw_bezoekrapporten\lib\vendor\symfony\lib\plugins\sfDoctri 
nePlugin\lib\vendor\doctrine\Doctrine\Connection.php on line 1239 
PHP Stack trace: 
PHP 1. {main}() D:\Internet\PHP\ijzerleeuw_bezoekrapporten\symfony:0 
PHP 2. include() D:\Internet\PHP\ijzerleeuw_bezoekrapporten\symfony:14 
PHP 3. sfDatabaseManager->shutdown() D:\Internet\PHP\ijzerleeuw_bezoekrapporten\lib\vendor\symfony\lib\database\sfDatabaseManager.class.php:0 
PHP 4. sfDoctrineDatabase->shutdown() D:\Internet\PHP\ijzerleeuw_bezoekrapporten\lib\vendor\symfony\lib\database\sfDatabaseManager.class.php:134 
PHP 5. Doctrine_Manager->closeConnection() D:\Internet\PHP\ijzerleeuw_bezoekrapporten\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\database\sfDoctr 
ineDatabase.class.php:165 
PHP 6. Doctrine_Connection->close() D:\Internet\PHP\ijzerleeuw_bezoekrapporten\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrin 
e\Manager.php:580 
PHP 7. Doctrine_Connection->clear() D:\Internet\PHP\ijzerleeuw_bezoekrapporten\lib\vendor\symfony\lib\plugins\sfDoctrinePlugin\lib\vendor\doctrine\Doctrin 
e\Connection.php:1268 

這是我的schema.yml,我用它來生成模型(PHP symfony的學說:內置mdeol):

InspectionReport: 
    actAs: { Timestampable: ~ } 
    columns: 
    customer_id: { type: integer(5), notnull: true } 
    username:  { type: string(255), notnull: true } 
    start_time:  { type: string(5) } 
    end_time:  { type: string(5) } 
    type:   { type: string(5) } 
    reason:   { type: string(4) } 
    contact:  { type: string(5) } 
    subject:  { type: string(5) } 
    remarks:  { type: string(5000) } 
    emailaddresses: { type: string(5) } 
    relations: 
    Complaints: 
     class: Complaint 
     refClass: ComplaintInspectionReport 
     local: id 
     foreign: complaint_id 
    Reviews: 
     class: Review 
     refClass: ReviewInspectionReport 
     local: id 
     foreign: review_id 

ComplaintInspectionReport: 
    columns: 
    complaint_id: { type: integer(4), primary: true } 
    inspection_report_id: { type: integer, primary: true } 
    relations: 
    Complaint: { onDelete: CASCADE, local: complaint_id, foreign: id } 
    InspectionReport: { onDelete: CASCADE, local: inspection_report_id, foreign: id } 

ReviewInspectionReport: 
    columns: 
    review_id: { type: integer, primary: true } 
    inspection_report_id: { type: integer, primary: true } 
    relations: 
    Review: { onDelete: CASCADE, local: review_id, foreign: id } 
    InspectionReport: { onDelete: CASCADE, local: inspection_report_id, foreign: id } 

Complaint: 
    columns: 
    id:   { type: integer, notnull: true } 
    description: { type: string(32), notnull: true } 
    contact:  { type: string(32) } 
    remark:  { type: string(50) } 

Review: 
    columns: 
    id:   { type: integer, notnull: true } 
    description: { type: string(32), notnull: true } 
    contact:  { type: string(32) } 
    remark:  { type: string(50) } 
    grade:   { type: string(1) } 
    email_address: { type: string(32) } 

我從模型/模式生成的schema.sql文件(PHP symfony的原則:建立-SQL):

CREATE TABLE complaint (id BIGINT AUTO_INCREMENT, description VARCHAR(32) NOT NULL, contact VARCHAR(32), remark VARCHAR(50), PRIMARY KEY(id)) ENGINE = INNODB; 
CREATE TABLE complaint_inspection_report (complaint_id INT, inspection_report_id BIGINT, PRIMARY KEY(complaint_id, inspection_report_id)) ENGINE = INNODB; 
CREATE TABLE inspection_report (id BIGINT AUTO_INCREMENT, customer_id BIGINT NOT NULL, username VARCHAR(255) NOT NULL, start_time VARCHAR(5), end_time VARCHAR(5), type VARCHAR(5), reason VARCHAR(4), contact VARCHAR(5), subject VARCHAR(5), remarks TEXT, emailaddresses VARCHAR(5), created_at DATETIME NOT NULL, updated_at DATETIME NOT NULL, PRIMARY KEY(id)) ENGINE = INNODB; 
CREATE TABLE review (id BIGINT AUTO_INCREMENT, description VARCHAR(32) NOT NULL, contact VARCHAR(32), remark VARCHAR(50), grade VARCHAR(1), email_address VARCHAR(32), PRIMARY KEY(id)) ENGINE = INNODB; 
CREATE TABLE review_inspection_report (review_id BIGINT, inspection_report_id BIGINT, PRIMARY KEY(review_id, inspection_report_id)) ENGINE = INNODB; 
ALTER TABLE complaint_inspection_report ADD CONSTRAINT complaint_inspection_report_complaint_id_complaint_id FOREIGN KEY (complaint_id) REFERENCES complaint(id) ON DELETE CASCADE; 
ALTER TABLE complaint_inspection_report ADD CONSTRAINT ciii FOREIGN KEY (inspection_report_id) REFERENCES inspection_report(id) ON DELETE CASCADE; 
ALTER TABLE review_inspection_report ADD CONSTRAINT riii FOREIGN KEY (inspection_report_id) REFERENCES inspection_report(id) ON DELETE CASCADE; 
ALTER TABLE review_inspection_report ADD CONSTRAINT review_inspection_report_review_id_review_id FOREIGN KEY (review_id) REFERENCES review(id) ON DELETE CASCADE; 

如果我運行SQL手動它工作正常,但使用時學說:插入-SQL返回我的錯誤。

我在想我的模式中的錯誤,但似乎無法得到它的保留。或者,也許它完全不同。

+0

你的模式沒問題。我們可以看到「投訴」模型類嗎? ('lib/model/doctrine/Complaint.class.php'&'lib/model/doctrine/ComplaintTable.class.php') – j0k

+0

@ j0k我已經添加了模型。 –

回答

1

我錯了,我只是生成類,並沒有嘗試加載SQL。

事實上,你有幾個誤區:

  • 一個表,你不應該定義列id,只要你不把它需要的主鍵,而不是增加,等等。否則對於每個中間表(ComplaintInspectionReport & ReviewInspectionReport)將造成對於Doctrine
  • 的麻煩,您不必重新定義relations。如果他們在父類中正確定義,則在此處不需要它們
  • 請注意integer類型。學說總是會使用integer,但是如果你定義了一個外部的integer(4),它導致由Doctrine生成的id自動生成,那麼當插入sql時,關係將會失敗。因爲一方面你有integer,另一方面integer(4)
  • 最後,請注意您在InspectionReport中定義的local密鑰。兩次使用id但您必須爲中間表定義本地密鑰,而不是當前密鑰。所以你必須爲兩者設置inspection_report_id

這裏是固定的模式:

InspectionReport: 
    actAs: { Timestampable: ~ } 
    columns: 
    customer_id: { type: integer(5), notnull: true } 
    username:  { type: string(255), notnull: true } 
    start_time:  { type: string(5) } 
    end_time:  { type: string(5) } 
    type:   { type: string(5) } 
    reason:   { type: string(4) } 
    contact:  { type: string(5) } 
    subject:  { type: string(5) } 
    remarks:  { type: string(5000) } 
    emailaddresses: { type: string(5) } 
    relations: 
    Complaints: 
     class: Complaint 
     refClass: ComplaintInspectionReport 
     local: inspection_report_id 
     foreign: complaint_id 
    Reviews: 
     class: Review 
     refClass: ReviewInspectionReport 
     local: inspection_report_id 
     foreign: review_id 

ComplaintInspectionReport: 
    columns: 
    complaint_id: { type: integer, primary: true } 
    inspection_report_id: { type: integer, primary: true } 

ReviewInspectionReport: 
    columns: 
    review_id: { type: integer, primary: true } 
    inspection_report_id: { type: integer, primary: true } 

Complaint: 
    columns: 
    description: { type: string(32), notnull: true } 
    contact:  { type: string(32) } 
    remark:  { type: string(50) } 

Review: 
    columns: 
    description: { type: string(32), notnull: true } 
    contact:  { type: string(32) } 
    remark:  { type: string(50) } 
    grade:   { type: string(1) } 
    email_address: { type: string(32) } 

不要忘記嘗試重新插入SQL前清除緩存。

+0

感謝您對我的模式的幫助,但不幸的是我仍然得到'類'投訴「必須是Doctrine_Record的子類」錯誤。我清除了我的緩存,刪除了舊的模型,表單和過濾器類,重新構建模型,sql並嘗試了insert-sql。它可能與Symfony版本有關嗎?我使用symfony 1.4.12-DEV(項目位置\ lib \ vendor \ symfony \ lib),因爲它是一個較老的項目。 –

+0

我試着將symfony版本更新到最新的1.4.19,但是這並沒有什麼區別... –

+0

您嘗試過'php symfony doctrine:build --all'?否則,我沒有其他想法..你必須有一些具體的處理投訴類。你必須搜索你所有的項目。 – j0k

相關問題