destroy_all and has_and_belongs_to_many

Use has:_many :through

class MatchedConnection # This is your Join Table, now as a real Model. The Table also now should have an primary key "id" column

belongs_to: matching_connection, :class_name => "Connection", :foreign_key => "match_id" belongs_to: requesting_connnection, :class_name => "Connection", :foreign_key => "request_id"

end

class Connection

  # a Request connection has these associations to its corresponding matches:   has_many :match_connections, :class_name => "MatchedConnection", foreign_key => "request_id"   has_many :matches,                           :through => :match_connections,                           :class_name => "Connection"                           :foreign_key => "match_id"

  # a Match connection has these associations to its corresponding requests:   has_many :requested_connections, :class_name => "MatchedConnection", :foreign_key => "match_id"   has_many :requests,                           :through => :request_connections,                           :class_name => "Connection"                           :foreign_key => "request_id" end

Explanation:

From a connection on the Match side to the request side:

->(match_id ) request_connections (request_id) -> requests

From a connection on the request side to the Match side:

->(request_id ) request_connections (match_id) -> requests

As the join Table now is a real model, you can access the join items: @Con = Connection.find(1) @con.match_connections.destroy_all

don't let the names of the associations i used confuse you, i don't know exactly what your Models should do, so the naming could be a little inconvinient.

My explanation is a little wrong, no time to correct it atm. Code should be fine though, just check it out.