繁体   English   中英

保存另一个表中的信息

[英]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

非常感谢 :)

我认为这个问题可以帮助您获取属性和值的列表。

在此之后,您需要设置动态字段,为此您可以使用方法send 像这样: @clientesultimasgestion.send("#{field_name}=",field_value)

我会替换:

    @clientesultimasgestion.save(f)

有:

    @clientesultimasgestion.update_attibutes(f.attributes)

此外,您想要的是复制表,请参阅https://stackoverflow.com/a/13237661/1197775

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM