[英]save information from another table
大家好,我有两张桌子:
clientesultimasgestiones clientesgestiones
我想把客户端的所有信息都放到clientesultimasgestiones上,但是我想逐场保存它,此时此刻我有这个
cnx = ActiveRecord::Base.connection
cnx.execute("truncate table clientesultimasgestiones")
@informacion = Clientesgestion.all
@informacion.each do |f|
@clientesultimasgestion = Clientesultimasgestion.new
@clientesultimasgestion.save(f)
Here will be the code to save field by field from clientesgestiones table to the another one
end
谢谢你的帮助
编辑:最后我这样做了:
cnx.execute("truncate table clientesultimasgestiones")
@informacion = Clientesgestion.all
@informacion.each do |f|
l = Clientesultimasgestion.new
l.persona_id = f.persona_id
l.fecha_gestion = f.fecha_gestion
l.clientestipologia_id = f.clientestipologia_id
l.observacion = f.observacion
l.user_id = f.user_id
l.fecha_acuerdo = f.fecha_acuerdo
l.valor_apagar = f.valor_apagar
l.clientestipologiaanterior_id = f.clientestipologiaanterior_id
l.clientesobligacion_id = f.clientesobligacion_id
l.save
end
非常感谢 :)
我会替换:
@clientesultimasgestion.save(f)
有:
@clientesultimasgestion.update_attibutes(f.attributes)
此外,您想要的是复制表,请参阅https://stackoverflow.com/a/13237661/1197775 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.