There is opportunity to simplify Mongoid's relation definitions, increase intuitiveness, and at the same time make them more powerful.
One particular issue I'm facing is over-usage of has_and_belongs_to_many ... inverse_of: nil
. The problem with this is that the inverse side of the relationship doesn't trigger any callbacks, which leads to out-of-sync data. It would be more natural to express this as belongs_to_many
and has_many
as per below.
Given two models, each can have the one of the following verbs to define a relation, so long as at least one side is belongs
: