为什么 Active Record 以 BigDecimal 符号的格式存储整数值?

Why Active Record storing integer value in the format of BigDecimal notation?

我是新手。观察以下屏幕截图,我有一个包含以下列的模型 Books

class CreateBooks < ActiveRecord::Migration
  def change
   create_table :books do |t|
     t.string :title
     t.text :author
     t.integer :price
     t.integer :book_id
    end
 end
end

稍后我向现有 table 添加一列,如下所示

class AddBookIdToBooks < ActiveRecord::Migration
  def change
    add_column :books, :book_id, :integer
  end
end

我使用 form helpers 在 table Book 中添加了一条记录。但是它以 BigDecimal 符号而不是 integer 的格式存储 book_id 值。

为什么要这样存储??提前致谢。

在此处观察以下屏幕截图

2.2.2 :023 > Book.all
Book Load (0.4ms)  SELECT "books".* FROM "books"
=> #<ActiveRecord::Relation [#<Book id: 7, title: "Wings Of Fire",   author: "kalam's", price: 120, created_at: "2015-12-09 09:57:10", updated_at: "2015-12-09 09:57:10", book_id: #<BigDecimal:4f39ea0,'0.1001E4',9(27)>>]> 

您不需要为您的模型添加 ID。 Rails 为你做。当您添加名为 "model"_id 的列时,Rails 推断它将引用其他 table(关联)。