title: What kind of relationship should be used for tables Transaction and User - Ruby on Rails?
body: <p>I am new learner. I just started learning more about Backend with Ruby on Rails.
  I have the following tables - User and User_Transaction.</p>
  <p>So basically I want to have a transaction which holds information about the sender and the receiver. This personally sounds to me more like a has_and_belongs_to_many relation. However, I am really confused in how to approach this and how should I include the 2 foreign keys.
  I am curious to learn more about this and I will be really happy if someone helps me :).</p>
  <p><strong>Migrations</strong>
  User</p>
  <pre><code>class CreateUsers &lt; ActiveRecord::Migration[6.0]
    def change
      create_table :users do |t|
        t.integer :username
        t.integer :password
        
  
        t.timestamps
      end
    end
  end
  </code></pre>
  <p>Transaction</p>
  <pre><code>class CreateTransactions &lt; ActiveRecord::Migration[6.0]
    def change
      create_table :transactions do |t|
        t.string :sender
        t.string:receiver
        t.decimal :amount
        
  
        t.timestamps
      end
  
    end
  end
  </code></pre>
  <p><strong>Models</strong></p>
  <p>Transaction</p>
  <pre><code>class ::Transaction &lt; ApplicationRecord
    #We have two users per transaction 'Sender' and 'Receiver'
      has_and_belongs_to_many :users
      # belongs_to :sender, :class_name =&gt; 'User'
      # belongs_to :receiver, :class_name =&gt; 'User'
  end
  
  </code></pre>
  <p>User</p>
  <pre><code>class User &lt; ApplicationRecord
    # has_many :accounts
    # has_many :transactions
    has_and_belongs_to_many :transactions
  
  end
  </code></pre>