database - Ruby on Rails, datatable. multiple records for one user -
i bit confused creating , inserting data in table.
for example, have user-table, users saved. payment-table should save payments made user a. payments not updated. once user registered, fills form types payments , there saved , nothing more. ( know sounds strange database based on statistical analysis of files. once file loaded, analysis done , data analysis (simple numbers) have stored. pro file there 1000 numbers stored , nothing updated). reference key user's id. so, should this:
class paymentstable < activerecord::migration def change create_table :payments |t| t.integer :user_id t.float :sum end end end
my problem not understand how can save 10 payemnts of user if specified t.float :sum 1 time.
thanks in advance
you want make entry of each of payments made user , want sum payments current way wrong.
you can create table of payments this,
class paymentstable < activerecord::migration
def change
create_table :payments |t|
t.integer :user_id
t.float :amount
end
end
so if sum amount column query like
user_payment = payment.where(:user_id=>params[:user_id)).first.sum(&:amount)
Comments
Post a Comment