Created
August 5, 2011 09:23
-
-
Save jzajpt/1127185 to your computer and use it in GitHub Desktop.
Mongoid 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 Accommodation | |
include Mongoid::Document | |
references_many :reservations | |
end |
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 Account | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
field :number, type: Integer | |
referenced_in :payer, polymorphic: true | |
references_one :reservation | |
end |
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
a = Accommodation.create | |
Reservation.create(accommodation:a) | |
/Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.9/lib/rails/commands/runner.rb:50:in `eval': You have a nil object when you didn't expect it! (NoMethodError) | |
You might have expected an instance of Array. | |
The error occurred while evaluating nil.push | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/relations/binding.rb:21:in `binding' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/relations/bindings/referenced/in.rb:23:in `bind' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/relations/proxy.rb:20:in `bind_one' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/relations/referenced/in.rb:24:in `block in initialize' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/relations/proxy.rb:35:in `init' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/relations/referenced/in.rb:22:in `initialize' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/relations/accessors.rb:44:in `new' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/relations/accessors.rb:44:in `create_relation' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/relations/accessors.rb:26:in `build' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/relations/accessors.rb:145:in `block (2 levels) in setter' | |
from /Users/jzajpt/Development/experiments/mongoid-bug/app/models/reservation.rb:15:in `create_accounts' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/callbacks.rb:420:in `_run_create_callbacks' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/callbacks.rb:94:in `run_callbacks' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/persistence/insertion.rb:25:in `block (2 levels) in prepare' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/callbacks.rb:421:in `_run_save_callbacks' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.0.9/lib/active_support/callbacks.rb:94:in `run_callbacks' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/persistence/insertion.rb:24:in `block in prepare' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/persistence/insertion.rb:22:in `tap' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/persistence/insertion.rb:22:in `prepare' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/persistence/operations/insert.rb:26:in `persist' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/persistence.rb:44:in `insert' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/persistence.rb:142:in `upsert' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/persistence.rb:162:in `block in create' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/persistence.rb:162:in `tap' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/mongoid-2.1.2/lib/mongoid/persistence.rb:162:in `create' | |
from (eval):1:in `<top (required)>' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.9/lib/rails/commands/runner.rb:50:in `eval' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.9/lib/rails/commands/runner.rb:50:in `<top (required)>' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.9/lib/rails/commands.rb:39:in `require' | |
from /Users/jzajpt/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.9/lib/rails/commands.rb:39:in `<top (required)>' | |
from script/rails:6:in `require' | |
from script/rails:6:in `<main>' |
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 Reservation | |
include Mongoid::Document | |
include Mongoid::Timestamps | |
field :number, type: Integer | |
referenced_in :accommodation | |
referenced_in :account | |
before_create :create_accounts | |
protected | |
def create_accounts | |
self.account = Account.create! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment