Home>

In Ruby on Rails, I want to display the total amount in the table well when many-to-many connection, but it does not work well and I am in trouble.
I searched a lot, but I couldn't find the corresponding article, so I would appreciate it if you could help me.

What you want to do

With Member1 and Member2, and RecordA and RecordB, the amount of RecordA is 500 yen and the amount of DataB is 200 yen.

I would like to pay [700 yen] when Member1 purchases both Record A and Record B, and [200 yen] when Member 2 purchases Record B.

I tried to make a table linkage, but I can't get it right.
What is the appropriate description for the model?

Thank you for your confirmation.


member table

create_table "members", force:: cascade do | t |
    t.string "MemberName"
    t.string "EventName"
    t.string "RecordName"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.string "payAmount"
    t.string "paidAmount"

Record table

create_table "records", force:: cascade do | t |
    t.string "RecordName"
    t.string "payMember"
    t.string "paidMember"
    t.integer "Amount"
    t.string "EventName"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false

Collaboration table

create_table "records_members", force:: cascade do | t |
    t.integer "Records_id", null: false
    t.integer "Members_id", null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.index ["Members_id"], name: "index_records_members_on_Members_id"
    t.index ["Records_id"], name: "index_records_members_on_Records_id"
  end

It doesn't have to work, so could you please edit the question and add the code that kyo tried, its actual behavior, and the expected behavior?

nekketsuuu♦2021-02-28 21:57:59