Ich versuche Schreib Code aus Zahlen von Belegnummern ausgeführt wird, mit den folgenden WertenWie erstelle ich Zeilen von einer laufenden Nummer?
Daten im Sinn:
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', ...}
Das Design:
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
Wie generiere ich die document_no in Transaktionen?
document = Transaction.new
document.document_type_code = 'PR'
document.document_no = ??????
...
document.save!
schreiben kann Does die ': id' Materie Oder könnte die Reihenfolge auch 'document_no => PR00001, document_no => PR00002' sein? Sie könnten auch eine ganze Zahl in document_no speichern und "document-no/document_type_code" zu einem zusammengesetzten Schlüssel machen. – Reactormonk