【发布时间】:2014-08-26 16:19:04
【问题描述】:
我正在尝试找出构建模型的最佳方法。每个用户可以有许多余额,但我想对每个用户强制执行每种货币的一个余额。应用程序控制记录的生成,所以这可能是矫枉过正。但是,这个问题让我很困惑,所以我想我会问社区。p>
如果这样做有意义,那么构建它的最佳方法是什么?
到目前为止我的迁移:
class CreateBalances < ActiveRecord::Migration
def change
create_table :balances do |t|
t.decimal :amount
t.integer :currency, default: 0, null: false # this will be an enum in the model
t.references :user, index: true
t.timestamps
end
end
end
TL;DR:每个 :currency per :user 之一
【问题讨论】:
标签: ruby-on-rails model rails-activerecord