Last active
December 24, 2015 06:59
-
-
Save we4tech/6760841 to your computer and use it in GitHub Desktop.
What if, we've more pictorial relationship syntax than syntactical sugar ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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