Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于join的优化 #538

Open
nanxia990105 opened this issue Feb 24, 2024 · 0 comments
Open

关于join的优化 #538

nanxia990105 opened this issue Feb 24, 2024 · 0 comments

Comments

@nanxia990105
Copy link

实体查询 中有这样的一段描述
观察生成的 SQL,我们发现 Ktorm 自动使用外键 left join 了 t_employee 的关联表 t_department。这是因为我们在表对象中声明 departmentId 这一列时使用 references 函数将此列绑定到了 Departments 表。在使用序列 API 的时候,Ktorm 会自动递归地 left join 所有关联的表,将部门表的数据一并查询出来,填充到 Employee.department 属性中

在使用了 references 函数来作为一对一join支持中 生成了如下类似的sql
select t_employee.id as t_employee_id, t_employee.name as t_employee_name, t_employee.job as t_employee_job, t_employee.manager_id as t_employee_manager_id, t_employee.hire_date as t_employee_hire_date, t_employee.salary as t_employee_salary, t_employee.department_id as t_employee_department_id, _ref0.id as _ref0_id, _ref0.name as _ref0_name, _ref0.location as _ref0_location from t_employee left join t_department _ref0 on t_employee.department_id = _ref0.id where t_employee.id = ?
left join t_department _ref0 on t_employee.department_id = _ref0.id 条件中 ref0.id 是默认使用了primaryKey方法的字段来作为 on的条件。
能否添加一个 类似 oneToOne 的方法, 用来额外指定在一对一关系中关联的字段。当然通过文档我了解primaryKey方法并不会作为实际的主键作用,只是字段的标识。但是我认为为了避免歧义或者说方法的单调性,增添一个类似oneToOne方法还是很有必要,望作者在百忙中看一下issues是否合理。以添加在后续的版本更新中

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant