Created
February 17, 2011 04:26
-
-
Save kasima/830977 to your computer and use it in GitHub Desktop.
Mongoid references_and_referenced_in association assignment bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.players = [] | |
game.save | |
# => true | |
game.reload | |
game.players.size | |
# => 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment