-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
class User include Mongoid::Document .... belongs_to :invitee, :class_name => 'User' has_one :inviter, :class_name => 'User', :inverse_of => :invitee ... end User.all.to_a.inspect => [#<User _id: 4e4a12d32e92d11f0d000001, _type: nil, email: "user@test.com", encrypted_password: "$2a$10$.GSwlja59LnMc9IqSBKAS.CRxJkUGoAoILYyF.LxLsdTx8I3p.586", remember_created_at: nil, reset_password_token: nil, reset_password_sent_at: nil, confirmation_token: "xFQ2afXhuaplgpHKxPMV", confirmed_at: nil, confirmation_sent_at: 2011-08-16 06:48:51 UTC, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, name: "Test User", gender: nil, date_of_birth: nil, admin: false, invited: true, invitee_id: BSON::ObjectId('4e4a12d32e92d11f0d000002')>, #<User _id: 4e4a12d32e92d11f0d000002, _type: nil, email: "user2@test.com", encrypted_password: "$2a$10$zHsp3aHMXGHIdxvu/94x.enpEyOjq.uby3mnKa45OJJqAEYZzLtCS", remember_created_at: nil, reset_password_token: nil, reset_password_sent_at: nil, confirmation_token: "x3tYAjZ41zzS4om3vIb0", confirmed_at: nil, confirmation_sent_at: 2011-08-16 06:48:51 UTC, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, name: "User2", gender: nil, date_of_birth: nil, admin: false, invited: true, invitee_id: BSON::ObjectId('4e4a12d32e92d11f0d000001')>]
Any of the following causes an infinite loop:
User.first.invitee = nil
User.first.invitee_id = nil
SystemStackError: stack level too deep
/Users/heinrich/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.1.0.rc5/lib/active_support/core_ext/time/calculations.rb:265:
I have debugged this a little bit and it's going back and forth between rails and mongoid code. I have found similar problem when :autosave => true on self referencing relationship.