Is creating table entry from another table entry and copying its value good practices?
1
vote
0
answers
42
views
Lets say I have
inventory_receives
table which contain many inventory_receive_entry
and also I have inventory
table which contain one inventory_receive_entry
Then in my application inventory_receives
instance has a method with function to loop for each inventory_receive_entry
that it have and creates inventory
by copying the attributes values from inventory_receive_entry
to inventory
Is this a good practices?
I'm confused should I copying the value from inventory_receive_entry
to inventory
or should I just refer the inventory_receive_entry
from inventory
my consideration about copying the value instead referring is the practicality since I not need to write complex query and such
but there are people that said about single source of truth and something like that
My schema from ruby on rails:
create_table "inventory_receives", force: :cascade do |t|
t.bigint "id"
t.bigint "supplier_id"
t.bigint "branch_id"
end
create_table "inventory_receives_entries", force: :cascade do |t|
t.bigint "id"
t.bigint "inventory_receive_id", null: false
t.bigint "product_id", null: false
t.integer "quantity", default: 0, null: false
t.datetime "expiry_date"
t.string "barcode", default: "", null: false
t.decimal "price", default: "0.0", null: false
t.string "batch_code", default: "", null: false
t.decimal "vat", default: "10.0", null: false
t.decimal "discount", default: "0.0", null: false
end
create_table "inventories", force: :cascade do |t|
t.bigint "id"
t.bigint "inventory_receive_entry_id", null: false
t.integer "quantity", default: 0, null: false
t.decimal "selling_price", default: "0.0", null: false
end
Asked by joyoy
(13 rep)
Feb 7, 2022, 01:50 PM
Last activity: Apr 25, 2022, 10:15 AM
Last activity: Apr 25, 2022, 10:15 AM