

def follow_joins(self, collected):
    prepared = [collected[self.model]]
    for metadata in self.join_list:
        inst = collected[metadata.src]
        try:
            joined_inst = collected[metadata.dest]
        except KeyError:
            joined_inst = collected[metadata.dest_model]
        mpk = (metadata.primary_key is not None)
        can_populate_joined_pk = (mpk and (metadata.attr in inst._data) and (getattr(joined_inst, metadata.primary_key.name) is None))
        if prepared:
            setattr(joined_inst, metadata.primary_key.name, inst._data[metadata.attr])
        if metadata.is_backref:
            can_populate_joined_fk = (mpk and (metadata.foreign_key is not None) and (getattr(inst, metadata.primary_key.name) is not None) and (joined_inst._data.get(metadata.foreign_key.name) is None))
            if can_populate_joined_fk:
                setattr(joined_inst, metadata.foreign_key.name, inst)
        setattr(inst, metadata.attr, joined_inst)
        prepared.append(joined_inst)
    return prepared

dataset/ETHPy150Open coleifer/peewee/peewee.py ModelQueryResultWrapper.follow_joins/VarMisuse@113/145 `can_populate_joined_pk`->`prepared`