【发布时间】:2015-03-08 09:37:04
【问题描述】:
我在 schema.rb 中声明了这个模型:
create_table "lot_reports", force: :cascade do |t|
t.integer "spaces_occupied"
t.integer "spaces_newly_occupied"
t.string "name"
t.time "time_stamp"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "lot_id"
end
当我尝试访问模型上的spaces_occupied 属性时,即使数据库显示该字段的值,我也会收到nil。
LotReport Load (0.5ms) SELECT "lot_reports".* FROM "lot_reports" ORDER BY "lot_reports"."id" ASC LIMIT 1
#=> #<LotReport id: 1, spaces_occupied: 107, spaces_newly_occupied: 153, name: "Cummerata Field", time_stamp: "2000-01-01 23:13:25", created_at: "2015-03-07 23:19:42", updated_at: "2015-03-07 23:19:42", lot_id: 1>
LotReport.first.spaces_occupied
LotReport Load (0.5ms) SELECT "lot_reports".* FROM "lot_reports" ORDER BY "lot_reports"."id" ASC LIMIT 1
#=> nil
不确定这里发生了什么。这是唯一存在此问题的属性;其他人返回我所期望的。
编辑:这里是 LotReport 源代码
class LotReport < ActiveRecord::Base
belongs_to :lot
def plot_array
[spaces_occupied, time_stamp]
end
end
【问题讨论】:
-
感谢编辑!
-
请发布您的
LotReport的源代码。
标签: ruby-on-rails ruby postgresql activerecord