Ruby on Rails - embedded associations in ruby on rails - ruby on rails tutorial - rails guides - rails tutorial - ruby rails
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
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
This to our Address model file:
embedded_in :user
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
- This will embed Address in our User model, adding a addresses method to our User class.