铁轨活动记录中的红宝石奇怪溢出

时间:2013-04-29 20:25:22

标签: ruby-on-rails ruby ruby-on-rails-3 activerecord

假设我有一个模型项目。数据表中有很多项目。项目与其他模型具有has_one关系(例如,价格)。我必须与create_price方法建立关系。

item.id #=> 95000

让我们开始......

price = item.create_price price: 500
price.item_id #=> 65556 // Why? Why 65556, not 95000?

来自项目:

CSV.foreach('file.csv', headers: true, col_sep: ';') do |row|
  Item.transaction do
    item = Item.create! article: row[0]
    gross = item.create_gross_price price: row[1]
  end
end

此代码生成此sql:

INSERT INTO `gross_prices` (`catalog_url`, `count`, `created_at`, `currency_type`, `delivery_tax`, `discount`, `item_id`, `price`, `updated_at`) VALUES (NULL, NULL, '2013-04-29 20:38:49', 'руб.', NULL, NULL, 65556, 52.0, '2013-04-29 20:38:49')

0 个答案:

没有答案