1
은 이전에 우리는 우리의 모델 has_one과의 관계 belongs_to했다 :비정상적인 레일 Mongoid 케이스
class Task
include Mongoid::Document
include Mongoid::Timestamps
has_one :output
end
class Output
include Mongoid::Document
include Mongoid::Timestamps
belongs_to :task
end
을하지만 우리는 지금 작업 내부 출력을 포함 할 계획입니다.
class Task
include Mongoid::Document
include Mongoid::Timestamps
embeds_one :output
end
class Output
include Mongoid::Document
include Mongoid::Timestamps
embedded_in :task
end
모든 것이 제대로 작동하지만 이전 버전과 호환되도록 만들려고합니다. 즉. 우리는 embed하기 전에 생성 된 출력을 원합니다. 이와
def output
Task.collection.find(_id: Moped::BSON::ObjectId(self.id)).first.output || Output.collection.find(task_id: Moped::BSON::ObjectId(self.id)).first
end
문제는 지금 task.output이 JSON 대신 출력 객체를 줄 것입니다 :
다음, 우리는 task.rb에서이 방법을했다. 그래서 우리는이 시나리오 또는이 경우에 대한 방향을 갖는
task = Task.new
output = task.create_output
output.task #=> not possible
누구나 할 수 없습니다.
잘 나는이 생각,하지만 난 작업과 출력의 만 이상의 기록이, 그래서이 의심되었다했다. .. – roxxypoxxy