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

fix: the mounted property type of arbitrary join fix #417 #418

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

JimmyDaddy
Copy link
Collaborator

fix #417

@JimmyDaddy JimmyDaddy linked an issue Feb 1, 2024 that may be closed by this pull request
});
assert.equal(posts.length, 1);
assert.ok(posts[0].users instanceof User);
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#417 比较棘手的地方就在与 join(OtherModel) 的时候,这个关联的结果是应该返回一条还是多条,之前是只返回一条,从 join 语义上来说应该默认返回多条,改成数组,但是这会是个 breaking change

在你的用例里面,能 work 的原因是 comment association 可能提前声明过,所以会按照声明的关联关系 hasMany: true 变成多条;但是我有些担心这样是不是太隐晦了,相当于 .join() 的时候,对关联的数据类型不容易预期

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实,我这里是如果原本有 association 关系绑定的话就按 association 来处理,否则统一按返回单条非数组来处理

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯呐,也是一个办法,就是也是一个 breaking change,我明天去 poll 一下我这边用户们的意见 :-/

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯呐,也是一个办法,就是也是一个 breaking change,我明天去 poll 一下我这边用户们的意见 :-/

其实也比较隐式。。join 的返回可能是数组可能是单条。返回的结果类型因为其他条件而变化了

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哦对,我当时想到一个办法是加一个 joinMany(),后者返回数组,前者保持不变

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哦对,我当时想到一个办法是加一个 joinMany(),后者返回数组,前者保持不变

好像 typeormsequelize 都是按我现在这个逻辑处理的

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不太一样吧?引用的这两个文档都是讲述关联关系配置的,也就是 leoric 的预知关联方式 https://leoric.js.org/zh/associations

.join() 方法的目的是用来编写临时的联表查询,期望结果一对一或者一对多,都是有可能的

@JimmyDaddy JimmyDaddy force-pushed the fix/417-the-mounted-property-type-of-arbitrary-join branch from efe2cf9 to 012ea6d Compare February 1, 2024 11:12
@JimmyDaddy JimmyDaddy force-pushed the fix/417-the-mounted-property-type-of-arbitrary-join branch from 012ea6d to 3369464 Compare February 1, 2024 11:19
Copy link

codecov bot commented Feb 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (47c56e6) 96.70% compared to head (3369464) 96.70%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #418   +/-   ##
=======================================
  Coverage   96.70%   96.70%           
=======================================
  Files          45       45           
  Lines        3669     3672    +3     
  Branches       72       72           
=======================================
+ Hits         3548     3551    +3     
  Misses        106      106           
  Partials       15       15           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

Successfully merging this pull request may close these issues.

the mounted property type of arbitrary join
2 participants