Skip to content

Instantly share code, notes, and snippets.

@kasima
Created February 17, 2011 04:24
Show Gist options
  • Save kasima/830974 to your computer and use it in GitHub Desktop.
Save kasima/830974 to your computer and use it in GitHub Desktop.
Mongoid destroy references_and_referenced_in_many bug
class Game
include Mongoid::Document
field :title
references_and_referenced_in_many :players
end
class Player
include Mongoid::Document
field :name
references_many :games
end
game = Game.new
3.times { |i| game.players << Player.new }
game.save
# => true
game.reload
game.players.size
# => 3
game.player_ids.size
# => 3
game.players.first.destroy
game.players.size
# => 2
game.player_ids.size
# => 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment