Heim  >  Fragen und Antworten  >  Hauptteil

ruby - active record更新关联表的字段值

有表users和表orders,rails生成的关联表是orders_users,现在可不可以在users_controller.rb中通过User更新orders_users表中的字段值,要怎么操作……

大家讲道理大家讲道理2758 Tage vor588

Antworte allen(1)Ich werde antworten

  • 迷茫

    迷茫2017-04-25 09:03:40

    关联两张表时,会有生成以下的方法,更新orders_users也是通过以下方法操作

    user.orders<<(object, ...)
    user.orders.delete(object, ...)
    user.orders.destroy(object, ...)
    user.orders=objects
    user.orders_singular_ids
    user.orders_singular_ids=ids
    user.orders.clear
    user.orders.empty?
    user.orders.size
    user.orders.find(...)
    user.orders.where(...)
    user.orders.exists?(...)
    user.orders.build(attributes = {})
    user.orders.create(attributes = {})
    user.orders.create!(attributes = {})

    http://guides.rubyonrails.org...

    http://guides.ruby-china.org/...

    Antwort
    0
  • StornierenAntwort