Properly handle LDL for polymorphic relations

LDL format for polymorphic relations is now handled correctly, and toJSON will include polymorphic info.