Ruby on Rails Embedded Associations


Example

Mongoid allows Embedded Associations:

  • One-to-one: embeds_one / embedded_in
  • One-to-many: embeds_many / embedded_in

To add an association (lets say the User embeds_many addresses), add this to your User file:

embeds_many :addresses

and this to your Address model file:

embedded_in :user

This will embed Address in your User model, adding a addresses method to your User class.