My Lift site uses Mongo as a database. Most of what's stored in Mongo as a JavaScript object was represented in Lift as a case class. But recently, I've had to change such an object to a
BsonRecord.
This worked wonderfully. I can now use Rogue to search inside of the BsonRecord, which is why I made the change in the first place.
However, today we noticed a very annoying side effect: the content of that original case class was also saved somewhere else as part of another polymorphous case class. So, basically, we have:
class Collection extends MongoRecord[...] {
// ...
// That used to be a MongoCaseClassListField:
object assets extends BsonRecordListField(this, MainItemType)
// ...
}
// This used to be a case class:
class MainItemType extends BsonRecord[...]
And elsewhere:
abstract trait GeneralItemType
class Preset extends MongoRecord[...] {
// ... metadata
object items extends MongoCaseClassListField[Preset, GeneralItemType](this) {override formats = ...}
// ... metadata
}
case class ItemType1(
item: MainItemType, // used to be a case class; is now a BsonRecord
// metadata....
) extends GeneralItemType
case class ItemType2(
thing: OtherItemType, // Completely different type.
// metadata....
) extends GeneralItemType
The MainItemType data inside of ItemType1 is supposed to be a copy, not a reference. We need it because the original may be gone by the time we look it up from within a Preset. When MainItemType was a case class, this was easy, as case classes are always serializable and easy to copy.
We weren't really looking at the presets, until today when someone noticed something that was not working. None of the MainItemTypes within presets were saving properly Now, based on what I understand:
- I cannot save the item field from inside of an ItemType1 instance.
- I cannot have a polymorphous BsonRecord inside of Preset
Now, tomorrow, I'm going to try to work around those limitations, but does some glaring omission or error on my part? I'm thinking of creating a "shadow" MainItemType as a case class and transfer the contents via JSON. I know it's ugly and dirty, but this is all i have so far.
Thanks!