Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
What if, we've more pictorial relationship syntax than syntactical sugar ?
class Message
include Mongoid::Document
include Mongoid::Timestamps
field :subject, type: String
field :content, type: String
belongs_to :replied_to, class_name: 'Message', inverse_of: :replies, touch: true
belongs_to :sender, class_name: 'User', inverse_of: :sent_messages
has_many :replies, class_name: 'Message', inverse_of: :replied_to
has_and_belongs_to_many :recipients, class_name: 'User', inverse_of: :received_messages
end
class Message
include Mongoid::Document
include Mongoid::Timestamps
field :subject, type: String
field :content, type: String
relation 'Message => self', as: :replied_to, touch: true
relation 'User => self', as: :sent_messages
relation 'self => Message', as: :replies, inverse_of: :replied_to
relation 'self => User <= self', as: :recipients, inverse_of: :received_message
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.