async def load_fk(self, info: SQLQueryInfo, records: Iterable[DataRecord]) -> Union[List, Iterable]:
        """
        :param info:
        :param records: the data got from database and filtered from permission
        :return:
        """

        # if not items, items is probably [], so return itself.
        # if not items: return items

        # 1. get tables' instances
        # table_map = {}
        # for column in info['loadfk'].keys():
        #     tbl_name = self.foreign_keys[column][0]
        #     table_map[column] = self.app.tables[tbl_name]

        # 2. get query parameters
        async def check(data, records):
            for column, fkvalues_lst in data.items():
                for fkvalues in fkvalues_lst:
                    pks = []
                    all_ni = True
                    vcls = self.app.tables[fkvalues['table']]

                    for i in records:
                        val = i.get(column, NotImplemented)
                        if val != NotImplemented:
                            all_ni = False
                        pks.append(val)

                    if all_ni:
                        logger.debug("load foreign key failed, do you have read permission to the column %r?" % column)
                        continue

                    # 3. query foreign keys
                    v = vcls(self.app, self._request)  # fake view
                    await v._prepare()
                    info2 = SQLQueryInfo()
                    info2.set_select(ALL_COLUMNS)
                    info2.add_condition(PRIMARY_KEY, SQL_OP.IN, pks)
                    info2.bind(v)

                    # ability = vcls.permission.request_role(self.current_user, fkvalues['role'])
                    # info2.check_query_permission_full(self.current_user, fktable, ability)

                    try:
                        fk_records, count = await v._sql.select_page(info2, size=-1)
                    except RecordNotFound:
                        # 外键没有找到值，也许全部都是null，这很常见
                        continue

                    # if not fk_records: continue
                    await v.check_records_permission(info2, fk_records)

                    fk_dict = {}
                    for i in fk_records:
                        # 主键: 数据
                        fk_dict[i[vcls.primary_key]] = i

                    column_to_set = fkvalues.get('as', column) or column
                    for _, record in enumerate(records):
                        k = record.get(column, NotImplemented)
                        if k in fk_dict:
                            record[column_to_set] = fk_dict[k]

                    if fkvalues['loadfk']:
                        await check(fkvalues['loadfk'], fk_records)

        await check(info.loadfk, records)
        return records
async def load_fk(self, info: SQLQueryInfo, records: Iterable[DataRecord]) -> Union[List, Iterable]:
        """
        :param info:
        :param records: the data got from database and filtered from permission
        :return:
        """

        # if not items, items is probably [], so return itself.
        # if not items: return items

        # 1. get tables' instances
        # table_map = {}
        # for column in info['loadfk'].keys():
        #     tbl_name = self.foreign_keys[column][0]
        #     table_map[column] = self.app.tables[tbl_name]

        # 2. get query parameters
        async def check(data, records):
            for column, fkvalues_lst in data.items():
                for fkvalues in fkvalues_lst:
                    pks = []
                    all_ni = True
                    vcls = self.app.tables[fkvalues['table']]

                    for i in records:
                        val = i.get(column, NotImplemented)
                        if val != NotImplemented:
                            all_ni = False
                        pks.append(val)

                    if all_ni:
                        logger.debug("load foreign key failed, do you have read permission to the column %r?" % column)
                        continue

                    # 3. query foreign keys
                    v = vcls(self.app, self._request)  # fake view
                    await v._prepare()
                    info2 = SQLQueryInfo()
                    info2.set_select(ALL_COLUMNS)
                    info2.add_condition(PRIMARY_KEY, SQL_OP.IN, pks)
                    info2.bind(v)

                    # ability = vcls.permission.request_role(self.current_user, fkvalues['role'])
                    # info2.check_query_permission_full(self.current_user, fktable, ability)

                    try:
                        fk_records, count = await v._sql.select_page(info2, size=-1)
                    except RecordNotFound:
                        # 外键没有找到值，也许全部都是null，这很常见
                        continue

                    # if not fk_records: continue
                    await v.check_records_permission(info2, fk_records)

                    fk_dict = {}
                    for i in fk_records:
                        # 主键: 数据
                        fk_dict[i[vcls.primary_key]] = i

                    column_to_set = fkvalues.get('as', column) or column
                    for _, record in enumerate(records):
                        k = record.get(column, NotImplemented)
                        if k in fk_dict:
                            record[column_to_set] = fk_dict[k]

                    if fkvalues['loadfk']:
                        await check(fkvalues['loadfk'], fk_records)

        await check(info.loadfk, records)
        return records
async def load_fk ( self , info : SQLQueryInfo , records : Iterable [ DataRecord ] ) -> Union [ List , Iterable ] : # if not items, items is probably [], so return itself. # if not items: return items # 1. get tables' instances # table_map = {} # for column in info['loadfk'].keys(): #     tbl_name = self.foreign_keys[column][0] #     table_map[column] = self.app.tables[tbl_name] # 2. get query parameters async def check ( data , records ) : for column , fkvalues_lst in data . items ( ) : for fkvalues in fkvalues_lst : pks = [ ] all_ni = True vcls = self . app . tables [ fkvalues [ 'table' ] ] for i in records : val = i . get ( column , NotImplemented ) if val != NotImplemented : all_ni = False pks . append ( val ) if all_ni : logger . debug ( "load foreign key failed, do you have read permission to the column %r?" % column ) continue # 3. query foreign keys v = vcls ( self . app , self . _request ) # fake view await v . _prepare ( ) info2 = SQLQueryInfo ( ) info2 . set_select ( ALL_COLUMNS ) info2 . add_condition ( PRIMARY_KEY , SQL_OP . IN , pks ) info2 . bind ( v ) # ability = vcls.permission.request_role(self.current_user, fkvalues['role']) # info2.check_query_permission_full(self.current_user, fktable, ability) try : fk_records , count = await v . _sql . select_page ( info2 , size = - 1 ) except RecordNotFound : # 外键没有找到值，也许全部都是null，这很常见 continue # if not fk_records: continue await v . check_records_permission ( info2 , fk_records ) fk_dict = { } for i in fk_records : # 主键: 数据 fk_dict [ i [ vcls . primary_key ] ] = i column_to_set = fkvalues . get ( 'as' , column ) or column for _ , record in enumerate ( records ) : k = record . get ( column , NotImplemented ) if k in fk_dict : record [ column_to_set ] = fk_dict [ k ] if fkvalues [ 'loadfk' ] : await check ( fkvalues [ 'loadfk' ] , fk_records ) await check ( info . loadfk , records ) return records
:param info:
        :param records: the data got from database and filtered from permission
        :return:
: param info : : param records : the data got from database and filtered from permission : return :