top-think / think-orm

Think ORM——the PHP Database&ORM Framework
Apache License 2.0
413 stars 171 forks source link

[3.0] 实现模型字段类型转换的统一接口 #592

Closed NHZEX closed 1 month ago

NHZEX commented 1 month ago

使模型能友好复用DTO对象支持各种场景

resolve #587

codecov-commenter commented 1 month ago

:warning: Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 83.33333% with 3 lines in your changes missing coverage. Please review.

Project coverage is 17.34%. Comparing base (e35f497) to head (0b608a0). Report is 33 commits behind head on 3.0.

Files Patch % Lines
src/model/concern/Attribute.php 83.33% 3 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## 3.0 #592 +/- ## ============================================ + Coverage 12.24% 17.34% +5.10% - Complexity 2965 2988 +23 ============================================ Files 64 64 Lines 7129 7171 +42 ============================================ + Hits 873 1244 +371 + Misses 6256 5927 -329 ``` | [Flag](https://app.codecov.io/gh/top-think/think-orm/pull/592/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=top-think) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/top-think/think-orm/pull/592/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=top-think) | `17.34% <83.33%> (+5.10%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=top-think#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

liu21st commented 1 month ago

其实可以 简化下方法名 用get set就行了

NHZEX commented 1 month ago

其实可以 简化下方法名 用get set就行了

说是模型的 getXxxAttr, setXxxAttr ? 还是接口方法名称简化?(用通用方法名称容易与业务代码冲突)

liu21st commented 1 month ago

modelReadValue 和 modelWriteValue

NHZEX commented 1 month ago

modelReadValue 和 modelWriteValue

modelGetValue,modelSetValue 这样?

PS: 一不小心点错按钮把你回答给编辑一次了😂

liu21st commented 1 month ago

modelReadValue 和 modelWriteValue

modelGetValue,modelSetValue 这样?

PS: 一不小心点错按钮把你回答给编辑一次了😂

直接就用get set就行了吧

NHZEX commented 1 month ago

modelReadValue 和 modelWriteValue模型读取值和模型写入值

modelGetValue,modelSetValue 这样? PS: 一不小心点错按钮把你回答给编辑一次了😂

直接就用get set就行了吧

get、set我还倾向于尽量少用,因为感觉没有约束力,只用于轻量级数据的处理。 这些DTO场景还是认为type合理些(其实更想要是类似于别的ORM提供的字段定义约束能力)。

PS:如果你觉得不合适就 close 吧,目前是通过重新 writeTransform、readTransform 能在项目端实现(就是有一点维护成本)。

liu21st commented 1 month ago

我的意思是 modelReadValue =》 get modelWriteValue => set 这样简化下

NHZEX commented 1 month ago

还是接口方法名称简化?(用通用方法名称容易与业务代码冲突)

理解了😂,简化是简化方法名对吧。不怕容易与用户代码产生冲突么?

liu21st commented 1 month ago

还是接口方法名称简化?(用通用方法名称容易与业务代码冲突)

理解了😂,简化是简化方法名对吧。不怕容易与用户代码产生冲突么?

冲突可能性不大吧 一般都是setXXX getXXX为主 直接使用get set为方法名的场景不多