@classmethod<EOL><INDENT>def _dereference(cls, documents, references):<DEDENT>
<EOL>for path, projection in references.items():<EOL><INDENT>if '<STR_LIT>' not in projection:<EOL><INDENT>continue<EOL><DEDENT>ids = set()<EOL>for document in documents:<EOL><INDENT>value = cls._path_to_value(path, document)<EOL>if not value:<EOL><INDENT>continue<EOL><DEDENT>if isinstance(value, list):<EOL><INDENT>ids.update(value)<EOL><DEDENT>elif isinstance(value, dict):<EOL><INDENT>ids.update(value.values())<EOL><DEDENT>else:<EOL><INDENT>ids.add(value)<EOL><DEDENT><DEDENT>ref = projection.pop('<STR_LIT>')<EOL>frames = ref.many(<EOL>{'<STR_LIT>': {'<STR_LIT>': list(ids)}},<EOL>projection=projection<EOL>)<EOL>frames = {f._id: f for f in frames}<EOL>for document in documents:<EOL><INDENT>value = cls._path_to_value(path, document)<EOL>if not value:<EOL><INDENT>continue<EOL><DEDENT>if isinstance(value, list):<EOL><INDENT>value = [frames[id] for id in value if id in frames]<EOL><DEDENT>elif isinstance(value, dict):<EOL><INDENT>value = {key: frames.get(id) for key, id in value.items()}<EOL><DEDENT>else:<EOL><INDENT>value = frames.get(value, None)<EOL><DEDENT>child_document = document<EOL>keys = cls._path_to_keys(path)<EOL>for key in keys[:-<NUM_LIT:1>]:<EOL><INDENT>child_document = child_document[key]<EOL><DEDENT>child_document[keys[-<NUM_LIT:1>]] = value<EOL><DEDENT><DEDENT>
Dereference one or more documents