mongoid_denormalize icon indicating copy to clipboard operation
mongoid_denormalize copied to clipboard

Denormalize entire document(s) as embedded

Open Startouf opened this issue 9 years ago • 0 comments

It would be nice to have the option to denormalize entire/parts documents as an embedded document ?

class User
  has_many_denormalized :likes, embedded_as: :embedded_likes
  # => has_many :likes
  # => embeds_many :embedded_likes
  # => Ensure self.likes.first will read embedded_likes
  # => Ensure self.likes.build() will build a real like
  # => etc.
end

class Like
  belongs_to :user
  belongs_to :likable
  field :extra_field_not_denormalized
  denormalize_document to: :user, in: :embedded_likes, embed_as: 'EmbeddedLike'
end

class EmbeddedLike
  embedded_in :user
  belongs_to :likable
  belongs_to :like
end

Startouf avatar Dec 20 '16 10:12 Startouf