前回に引き続き、MongoDB で Rails アプリを作る話。 今回は関連づけに挑戦だ。 参考資料: http://mongoid.org/docs/associations app/documents/person.rb に has_one :address を追加。 class Person include Mongoid::Document field :first_name field :last_name has_one :address def full_name "#{first_name} #{last_name}" end end app/documents/address.rb を作成。ただし、ほとんど参考資料からのパクリ。 class Address include Mongoid::Document field :street field :city field