2015-01-10 53 views
0

爲什麼Grails的未填充數據我有以下的引導類通過引導

import shoppingsolutionproject.Category; 
import shoppingsolutionproject.Item 

class BootStrap { 

    def dataSource 

    def init = { servletContext -> 
     new Category(description: 'Car').save() 
     new Category(description: 'Truck').save() 
     new Item(productNumber:1, name:"First Product", description: "This is the first product I'm adding for testing", 
       shippingCost: 4.99, url: '/first', retailPrice: 19.99, salePrice: 16.99, category: 'Car').save() 
     new Item(productNumber:2, name:"Second Product", description: "This is the second product I'm adding for testing", 
       shippingCost: 4.99, url: '/second', retailPrice: 19.99, category: 'Truck').save() 
     new Item(productNumber:3, name:"First/Second Product", description: "This is the first/second(so third) product I'm adding for testing", 
       shippingCost: 4.99, url: '/second', retailPrice: 17.99, category: 'Truck').save() 
    } 
    def destroy = { 
    } 
} 

當我啓動Grails的,雖然,我沒有做的類別或項目預先填充...任何想法,爲什麼?

+1

很有可能您有驗證錯誤。驗證這一點的最快方法是將'failOnError:true'添加到'.save()'中,如下所示:'.save(failOnError:true)'。這應該會告訴你很多由於驗證錯誤而失敗的事情。 –

+0

@JoshuaMoore你是對的,我使用字符串'Car'作爲類別而不是類別對象,我創建了 –

+0

與論壇網站不同,我們不使用「謝謝」或「任何幫助讚賞」或簽名[so ]。請參閱「[應該'嗨','謝謝',標語和致敬從帖子中刪除?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be - 從帖子中刪除)。順便說一句,它是「提前致謝」,而不是「感謝先進」。 –

回答

3

很有可能您有驗證錯誤。

驗證此方法的最快方法是將failOnError: true添加到您的.save()像這樣:.save(failOnError: true)

這應該會顯示很多由於驗證錯誤而失敗的東西。