Skip to content

Instantly share code, notes, and snippets.

@we4tech
Last active December 24, 2015 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save we4tech/6760841 to your computer and use it in GitHub Desktop.
Save we4tech/6760841 to your computer and use it in GitHub Desktop.
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