Ton*_*ony 4 ruby enums activerecord ruby-on-rails
我有一个枚举,它有一个存储值,但getter返回nil.
我有以下代码:
class Property < ActiveRecord::Base
enum building_type: [
:none_building_type, :pre_war_low_rise, :pre_war_mid_rise,
:pre_war_high_rise, :post_war_low_rise, :post_war_mid_rise,
:post_war_high_rise, :pre_war_loft, :post_war_loft, :pre_war_hotel,
:post_war_hotel
]
Run Code Online (Sandbox Code Playgroud)
如果我在控制台中执行以下操作:
Property.last
Run Code Online (Sandbox Code Playgroud)
我明白了
Property Load (0.8ms) SELECT "properties".* FROM "properties" ORDER BY "properties"."id" DESC LIMIT 1
=> #<Property id: 3, created_at: "2014-11-17 15:39:34", updated_at: "2014-11-17 16:28:48", name: "PropertyName", property_type: 1, description: "adsdsaads", building_type: "4">
Run Code Online (Sandbox Code Playgroud)
但如果我这样做
Property.last.building_type
Run Code Online (Sandbox Code Playgroud)
我明白了
Property Load (0.5ms) SELECT "properties".* FROM "properties" ORDER BY "properties"."id" DESC LIMIT 1
=> nil
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1548 次 |
最近记录: |