Rails3, Mongoid, 오이. user_id 필드를 설정할 수 없습니다 : 잘못된 ObjectId 형식
class Account
include Mongoid::Document
include Mongoid::Timestamps
referenced_in :user
end
class User
include Mongoid::Document
include Mongoid::Timestamps
...
references_one :account
...
end
그리고 다음 시나리오 (reference_one 연관을 설정하려고합니다) :
Scenario: Client views his account
Given the following accounts:
| user_id |
| 1123322131 |
.....
그리고 다음 단계 :
Given /^the following accounts:$/ do |class_name, table|
table.hashes.each do |attributes|
Account.create(attributes)
end
end
Given /^the following accounts:$/ do |class_name, table|
table.hashes.each do |attributes|
Account.create(attributes)
end
end
xucx를 실행하려고하면 항상 오류가 발생합니다.
illegal ObjectId format (BSON::InvalidObjectId)
./features/step_definitions/common_steps.rb:7:in `block (2 levels) in <top (required)>'
./features/step_definitions/common_steps.rb:6:in `each'
./features/step_definitions/common_steps.rb:6:in `/^the following accounts:$/'
features/manage_accounts.feature:8:in `And the following accounts:'
역 추적의 전체 버전 : https://gist.github.com/433ea982d876e1b1fa27
I use : Rails 3.0.3, Ruby 1.9.2, 오이 1.9.4, 기계공 2, mongoid. 내 Gemfile
내가 뭘 잘못 했니?
UPD. 그렇게 명백하게 행동하지 :
> a = Account.create :user_id => "123"
BSON::InvalidObjectId: illegal ObjectId format
> a = Account.create :user_id => 123
=> #<Account _id: 4ceedf055e6f991aef000005, created_at: 2010-11-25 22:11:17 UTC, updated_at: 2010-11-25 22:11:17 UTC, user_id: 123>
> a = Account.create :user_id => "4ceede9b5e6f991aef000007"
=> #<Account _id: 4ceedf1b5e6f991aef000006, created_at: 2010-11-25 22:11:39 UTC, updated_at: 2010-11-25 22:11:39 UTC, user_id: BSON::ObjectId('4ceede9b5e6f991aef000007')>
UPD를 참조하십시오 해결책은 "4ceede9b5e6f991aef000007"와 같은 ID를 사용합니다 – petRUShka
사용자를 식별하고 Mongoid에게 알려주는'username' 또는'email'와 같은 오이 사양에 다른 필드를 사용 하시길 권합니다. – bowsersenior
나는이 방법을 이해하려고 노력했다. 당신이 나를 도우면 위대 할 것이다. http://stackoverflow.com/questions/4281386/rails- 오이 만든 개체와 협회 – petRUShka