The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
jonathanchoo

求教 Beego 的 ORM 里的 InsertOrUpdate 方法怎么更新指定的列

  •  
  •   jonathanchoo · Nov 3, 2020 · 3110 views
    This topic created in 2042 days ago, the information mentioned may be changed or developed.

    不管是

    Oconnect.InsertOrUpdate(nc, fmt.Sprintf("%s=%s+%s", "col_name", "col_name", "mock_value"))
    

    还是

    Oconnect.InsertOrUpdate(nc, fmt.Sprintf("%s=%s", "col_name", "mock_value"))
    

    依然没用啊。。

    求教

    5 replies    2022-07-05 14:14:01 +08:00
    harlen
        1
    harlen  
       Nov 3, 2020
    InsertOrUpdate 的意思是, 如果要插入的行已经存在,那就更新这条数据。 不能用来更新其他行的数据哦。
    jonathanchoo
        2
    jonathanchoo  
    OP
       Nov 3, 2020
    @harlen
    就是更新已存在的啊,我不想更新 created_at 的话,怎么做呢
    ninjashixuan
        3
    ninjashixuan  
       Nov 3, 2020
    如果是单纯想更新已存在的 update 不就行了,为什么要 InsertOrUpdate?
    harlen
        4
    harlen  
       Nov 3, 2020
    nc 中不存在 created_at 就不会更新了,如果还是更新了,你应该检查一下是生成的 sql 更新了这个字段,还是数据库的字段设置了在更新的时间更新
    jonathanchoo
        5
    jonathanchoo  
    OP
       Jul 5, 2022
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1760 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 16:14 · PVG 00:14 · LAX 09:14 · JFK 12:14
    ♥ Do have faith in what you're doing.