polyglot/app/models/connection.rb

15 lines
412 B
Ruby
Raw Permalink Normal View History

class Connection < ApplicationRecord
belongs_to :user
belongs_to :contact, class_name: 'User', foreign_key: 'contact_id'
after_create :create_inverted_connection
private
def create_inverted_connection
unless Connection.where('user_id = ? and contact_id = ?', self.contact.id, self.user.id).length > 0
2018-08-29 10:39:51 +00:00
inverted = Connection.create!(user: self.contact, contact: self.user)
end
end
end