簡體   English   中英

Rails activerecord .select導致對象具有所有nil屬性

[英]Rails activerecord .select causing object to have all nil attributes

我正在使用Rails 3.2.13,Ruby 2.0.0p-p247和Spree 2.0.3。

如果我運行以下命令,則在rails控制台或我的實際應用程序中使用activerecord: Spree::Product.select(:permalink).first我得到#<Spree::Product permalink: nil>

但是,如果我運行Spree::Product.first.permalink ,則會得到"test" (預期的永久鏈接)。 另外, Spree::Product.first返回產品的整個activerecord關系。

我嘗試在RAILS_ENV=development rails c運行Spree::Product.create(name: "test", price: "100") ,它可以按預期運行。 如果我嘗試在RAILS_ENV=test rails c嘗試, NoMethodError: undefined method '[]' for nil:NilClass得到一個SQL回滾,以及一個NoMethodError: undefined method '[]' for nil:NilClass

知道為什么僅在測試環境中會發生這種情況嗎?

原來這是spreei18n gem的一個錯誤,我提交了一個請求請求。

https://github.com/spree/spree/commit/09b55f7be8720f0d6d16822f4ce23c961d1c66f5

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM