I have a query in my code as below
@sqladdpayment = "INSERT INTO payments (orderid, ttlprodcost, paytype,
paystatus,created_at,updated_at,userid,storeid)
VALUES ('" + session[:ordersid] + "', '" + session[:totalcost] + "', '"
+ "1"+ "', '" + "complete" +"',current_date, current_date, '"+"1"+"','"+ "1"+"')"
Here the table payments
and primary key is orderid
. Now, I know if I convert this to the ActiveRecord
way then I will not have to put update_date
, current_date
because it will put that on it's own. It will also put orderid
on it's own also (auto_increment
).
I am looking for a way to convert the above query to ActiveRecord
Rails way but still be able to put orderid
on my own (session[:ordersid]
). I do not want to rely on auto_increment
because then I will have to refactor lot of the other code. This might be a quick and dirty fix but I want to know whether this type of flexibility is offered in rails?
I have wondered about this question many times. Why won't rails allow me to have that flexibility?