Guest User

Untitled

a guest
Dec 14th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. class Artist
  2. include Mongoid::Document
  3. field :name, type: String
  4. embeds_many :instruments
  5. end
  6.  
  7. class Instrument
  8. include Mongoid::Document
  9. field :name, type: String
  10. embedded_in :artist
  11. end
  12.  
  13. # Find the first artist named "Syd Vicious" and create an embedded bass
  14. # document for him. Of course he'll smash it within the next few minutes,
  15. # but no worries we can delete it later.
  16. Artist.where(name: "Syd Vicious").first.tap do |artist|
  17. artist.instruments.create(name: "Bass")
  18. end
Add Comment
Please, Sign In to add comment