Skip to content

Instantly share code, notes, and snippets.

@tal
Created April 6, 2011 02:55
Show Gist options
  • Select an option

  • Save tal/905046 to your computer and use it in GitHub Desktop.

Select an option

Save tal/905046 to your computer and use it in GitHub Desktop.
>> m = Match.first
=> #<Match _id: 4d9bce2458f68fbb67000001, user_ids: [1, 2], _id: BSON::ObjectId('4d9bce2458f68fbb67000001'), _type: nil>
>> m.players.create(:user_id => 1)
NoMethodError: undefined method `name' for nil:NilClass
class Match
include Mongoid::Document
field :user_ids, :type => Array, :default => []
embeds_many :players
end
class Player
include Mongoid::Document
field :first_name, :type => String
field :score, :type => Float, :default => 0.0
field :user_id, :type => Integer
embedded_in :match, :inverse_of => :matches
embeds_many :points
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment