我正在尝试从文档编号编写运行编号的代码,具有以下值
牢记数据:
document_types records :
{:document_type_code => 'PR', :running_no => 2, ...}
{:document_type_code => 'SO', :running_no => 1, ...}
transactions records :
{:id => 1, :document_no=> 'PR000001', :document_type_code=> 'PR', ...}
{:id => 2, :document_no=> 'SO000001', :document_type_code=> 'SO', ...}
{:id => 3, :document_no=> 'PR000002', :document_type_code=> 'PR', ...}
该设计:
create_table :runnings do |t|
t.string :document_type_code, :null => false, :limit => 2
t.integer :running_no, :null => false, :default => 0
...
t.timestamps
end
create_table :transactions do |t|
t.string :document_no, :null => false
t.string :document_type_code, :null => false, :limit => 2
...
t.timestamps
end
如何在 Transactions 中生成 document_no?
document = Transaction.new
document.document_type_code = 'PR'
document.document_no = ??????
...
document.save!