Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题描述
动态 API 中,同一个模板配置多个 api ,它们返回的数据都是一样的。
问题复现
users表的数据,根据配置,test2应该返回adminRoleModel 对应表admin_role的数据{ "status": 0, "msg": "", "doNotDisplayToast": 0, "_debug": { "sql": [ "[17.05 ms] select * from `cache` where `key` in ('admin_has_table_admin_relationships')", "[3.01 ms] select * from `cache` where `key` in ('admin_relationships')", "[3.6 ms] select * from `personal_access_tokens` where `personal_access_tokens`.`id` = 1 limit 1", "[2.92 ms] select * from `admin_users` where `admin_users`.`id` = 1 limit 1", "[5.94 ms] update `personal_access_tokens` set `last_used_at` = '2024-09-27 08:56:32', `personal_access_tokens`.`updated_at` = '2024-09-27 08:56:32' where `id` = 1", "[3.47 ms] select `admin_roles`.*, `admin_role_users`.`user_id` as `pivot_user_id`, `admin_role_users`.`role_id` as `pivot_role_id`, `admin_role_users`.`created_at` as `pivot_created_at`, `admin_role_users`.`updated_at` as `pivot_updated_at` from `admin_roles` inner join `admin_role_users` on `admin_roles`.`id` = `admin_role_users`.`role_id` where `admin_role_users`.`user_id` = 1", "[2.78 ms] select * from `admin_apis` where `path` = '\/test1' limit 1", "[2.61 ms] select * from `admin_apis` where `path` = 'test1' limit 1", "[5.19 ms] select * from `admin_apis` where `template` = 'Slowlyo\\OwlAdmin\\Support\\Apis\\DataListApi' limit 1", "[5.6 ms] select column_name as `name`, data_type as `type_name`, column_type as `type`, collation_name as `collation`, is_nullable as `nullable`, column_default as `default`, column_comment as `comment`, generation_expression as `expression`, extra as `extra` from information_schema.columns where table_schema = 'owl_admin' and table_name = 'users' order by ordinal_position asc", "[2.57 ms] select count(*) as aggregate from `users`" ] }, "data": { "items": [], "total": 0 } }{ "status": 0, "msg": "", "doNotDisplayToast": 0, "_debug": { "sql": [ "[10.47 ms] select * from `cache` where `key` in ('admin_has_table_admin_relationships')", "[3.42 ms] select * from `cache` where `key` in ('admin_relationships')", "[5.79 ms] select * from `personal_access_tokens` where `personal_access_tokens`.`id` = 1 limit 1", "[3.85 ms] select * from `admin_users` where `admin_users`.`id` = 1 limit 1", "[6.3 ms] update `personal_access_tokens` set `last_used_at` = '2024-09-27 08:56:24', `personal_access_tokens`.`updated_at` = '2024-09-27 08:56:24' where `id` = 1", "[3.17 ms] select `admin_roles`.*, `admin_role_users`.`user_id` as `pivot_user_id`, `admin_role_users`.`role_id` as `pivot_role_id`, `admin_role_users`.`created_at` as `pivot_created_at`, `admin_role_users`.`updated_at` as `pivot_updated_at` from `admin_roles` inner join `admin_role_users` on `admin_roles`.`id` = `admin_role_users`.`role_id` where `admin_role_users`.`user_id` = 1", "[2.74 ms] select * from `admin_apis` where `path` = '\/test2' limit 1", "[2.48 ms] select * from `admin_apis` where `path` = 'test2' limit 1", "[4.11 ms] select * from `admin_apis` where `template` = 'Slowlyo\\OwlAdmin\\Support\\Apis\\DataListApi' limit 1", "[5.02 ms] select column_name as `name`, data_type as `type_name`, column_type as `type`, collation_name as `collation`, is_nullable as `nullable`, column_default as `default`, column_comment as `comment`, generation_expression as `expression`, extra as `extra` from information_schema.columns where table_schema = 'owl_admin' and table_name = 'users' order by ordinal_position asc", "[2.78 ms] select count(*) as aggregate from `users`" ] }, "data": { "items": [], "total": 0 } }问题原因
getApiRecord方法实现的是形成了单例模式,同样的模板 apiRecord 的值都是一样的。
getApiByTemplate的实现为:查询的结果也只会是模板的默认排序的第一条数据。
解决方案
添加 setApiRecord 方法,并且在 AdminApiController 中使用该方法设置正确的 apiRecord。