mirror of
https://github.com/kingomarnajjar/curly-happiness.git
synced 2026-07-26 06:37:18 +10:00
12 lines
536 B
Ruby
12 lines
536 B
Ruby
class Conversation < ActiveRecord::Base
|
|
belongs_to :sender, :foreign_key => :sender_id, class_name: 'User'
|
|
belongs_to :recipient, :foreign_key => :recipient_id, class_name: 'User'
|
|
has_many :messages, dependent: :destroy
|
|
|
|
validates_uniqueness_of :sender_id, :scope => :recipient_id
|
|
|
|
scope :between, -> (sender_id,recipient_id) do
|
|
where("(conversations.sender_id = ? AND conversations.recipient_id =?) OR (conversations.sender_id = ? AND conversations.recipient_id =?)", sender_id,recipient_id, recipient_id, sender_id)
|
|
end
|
|
|
|
end
|