def _file_model(cls):
        """Find the top-level model stored in this model's path."""
        model = getattr(cls, '_cached_file_model', unspecified)
        if model is not unspecified:
            return model

        path = cls.opts.path
        model = cls
        while True:
            if model.opts.owner:
                try:
                    owner = model._fields[model.opts.owner].model
                    path = re.sub(r'{{self.{}(\.|}})'.format(model.opts.owner),
                                  '{self\\1', path)
                    if owner is not model and owner.opts.path == path:
                        model = owner
                        continue
                except KeyError:
                    pass
            cls._cached_file_model = model
            return model
Find the top-level model stored in this model's path.
portia_server/portia_orm/base.py