Mamy model podstawowy z osadzonym produktu:Mongoid 2.4 Zapytania dla osadzonych Dokumentu przez ID Niezastosowanie
class Entry
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Spacial::Document
embeds_many :items, cascade_callbacks: true
...
class Item
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Spacial::Document
embedded_in :entry
...
Jeśli kwerendy Mongo bezpośrednio do wpisu przez Item ID:
{"items._id" : ObjectId("50536b18baa072000f000360")}
powraca aktu:
505363b36181ce00020006b1 { "created_at": "2012-09-14T17: 04: 51Z", "elementy": [{ "_ id": "50536b1a2b17b3 .. .
Jednak kiedy zapytanie poprzez Mongoid:
irb(main):002:0> Entry.where('items._id' => '50536b18baa072000f000360')[0]
=> nil
Wszystkie inne zapytania pracy (dla pozostałych pól na przedmioty i pól na wejściu). Ale nie dla id.
Używamy mongoid (2.4.12).
lub w moim przypadku, 'motorowerem :: BSON :: ObjectId ('50536b18baa072000f000360')' w celu wyleczenia niezdefiniowanej metody '\' __bson_dump__”dla BSON :: ObjectId'. Whew! –
Użyj Moped :: BSON :: ObjectId w Mongoid 3 – Obie
To nie zadziała dla Mongoida 4.0.0.beta1 –