-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
Simple relations, company has many embedded operations, and operation has many inventoryoperation.
class Company include Mongoid::Document field :name, type: String embeds_many :operations end
class Operation include Mongoid::Document field :name, type: String has_many :inventory_operations embedded_in :company end
class InventoryOperation include Mongoid::Document field :quantity, type: Integer, default: 0 belongs_to :inventory belongs_to :operation end
Result when doing the search:
[1] pry(main)> io = InventoryOperation.all[0] => #<InventoryOperation _id: 51c859a6280b745f87000002, quantity: 400,inventory_id: "51d09bf6280b745f5b000001", operation_id: "51a721f0236f4483a2000002"> **[2] pry(main)> Operation.find(io.operation_id)** Mongoid::Errors::DocumentNotFound: Problem: Document(s) not found for class Operation with id(s) 51a721f0236f4483a2000002. Summary: When calling Operation.find with an id or array of ids, each parameter must match a document in the database or this error will be raised. .... Resolution: Search for an ... from /Users/xxx/.rvm/gems/ruby-1.9.3-head/gems/mongoid-3.1.4/lib/mongoid/criteria.rb:464:in `check_for_missing_documents!' [3] pry(main)> os = Company.first.operations.map { |e| e.id}; **[4] pry(main)> Operation.find(io.operation_id)** => #<Operation _id: 51a721f0236f4483a2000002, created_at: 2013-05-30 09:54:56 UTC, updated_at: 2013-09-06 16:24:48 UTC, name: "Admin"> [5] pry(main)>
in [2], we can't find the document, but in [3] after we visit all operations, we can find the same operation_id in [4]
is this the supposed behavior?