Skip to content

Instantly share code, notes, and snippets.

@tagrudev
Last active December 16, 2015 03:39
Show Gist options
  • Save tagrudev/5371797 to your computer and use it in GitHub Desktop.
Save tagrudev/5371797 to your computer and use it in GitHub Desktop.
Conversation Flow // Mongoid
class Conversation
include Mongoid::Document
include Mongoid::Timestamps
has_and_belongs_to_many :participants, :class_name => 'User', inverse_of: :conversations
embeds_many :messages, :class_name => 'Message'
end
class Message
include Mongoid::Document
include Mongoid::Timestamps
embedded_in :conversation
belongs_to :user
field :seen, :type => Mongoid::Boolean, :default => false
field :body
end
class User
include Mongoid::Document
include Mongoid::Timestamps
has_and_belongs_to_many :conversations, class_name: 'Conversation', inverse_of: :participants
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment