2009-05-29 84 views
3

比方說,我有YAML方案看起來就像是:爲什麼我得到「驗證失敗」一個保存在Symfony 1.2的學說?

Note: 
    options: 
    type: MyISAM 
    collate: utf8_unicode_ci 
    charset: utf8 
    actAs: { Timestampable: ~ } 
    columns: 
    content: { type: string, notnull: true} 
    order_id: int(5) 
    user_id : int 
    relations: 
    User: 
     foreignAlias: Notes 
     local: user_id 
     foreign: id 
     type: one 
     foreignType: man 
     onDelete: CASCADE 

當執行:

$note->setOrderId(0); 
$note->save(); 

,我發現了以下錯誤:

1 validator failed on order_id (type) 

MySQL的商店ORDER_ID爲BIGINT (20)。

我使用Ubuntu 9.10,Symfony的1.2,PHP 5和MySQL 5

編輯:

得到了暗示,如果我刪除的文件YAML的大小都不在話下,我得到一個第二order_id(長度)驗證錯誤:-)

+0

我有同樣的問題,但在1.4。我在模式中將「字符串」更改爲「浮點數」...但在save()上我有這個錯誤。 – Manu 2012-04-24 08:52:28

回答

2

我明白了。用「整數」替換「int」並去掉大小就是個竅門。現在YAML文件看起來像:

Note: 
    options: 
    type: MyISAM 
    collate: utf8_unicode_ci 
    charset: utf8 
    actAs: { Timestampable: ~ } 
    columns: 
    content: { type: string, notnull: true} 
    order_id: integer 
    user_id : integer 
    relations: 
    User: 
     foreignAlias: Notes 
     local: user_id 
     foreign: id 
     type: one 
     foreignType: man 
     onDelete: CASCADE 

我想,因爲其他人在網絡上也有類似的錯誤,解決了「串」代替「VARCHAR」。

如果有人陷成和閱讀這個答案,在他們的名字啤酒:-)

0

我知道這是老了......

我只是想我會澄清,有效的原則類型是「整數」,「字符串」,「浮點數」,「十進制」,「對象」,「clob」,「blob」,「枚舉」,「數組」。

然後,Doctrine將原則類型轉換爲所選後端的正確數據庫類型。

這就是爲什麼「int」失敗的類型驗證程序,但「整數」的作品。