def flatten(self, primary, **related):
        flat = {}
        # Remove id and reference id fields
        primary.pop('_id', None)
        for fname in self._relationships.keys():
            primary.pop(fname, None)
            
        transforms = self.field_transforms.get(self.primary_collection_name)
        if transforms:
            primary = self.transform_fields(primary, transforms)

        # Merge in the related data
        for name, data in related.items():
            # Prefix fields on related models for better readability in the
            # final output data, to prevent clobbering any duplicate keys
            # and to make the fields more accessible to our transformers
            # and calculators.
            data.pop('_id', None)
            transforms = self.field_transforms.get(name)
            if transforms:
                data = self.transform_fields(data, transforms)
            flat.update(data)

        flat.update(primary)
        flat.update(self.get_calculated_fields(flat))

        return flat
Custom iterator to use entries instead of the object itself
dataset/ETHPy150Open openelections/openelections-core/openelex/base/bake.py/Roller.flatten--crossover with--dataset/ETHPy150Open jpsenior/threataggregator/threataggregator.py/RepDB.__iter__