-
Notifications
You must be signed in to change notification settings - Fork 25
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
base: master
Are you sure you want to change the base?
fix: the mounted property type of arbitrary join fix #417 #418
Conversation
}); | ||
assert.equal(posts.length, 1); | ||
assert.ok(posts[0].users instanceof User); | ||
}); |
There was a problem hiding this comment.
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() 的时候,对关联的数据类型不容易预期
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
确实,我这里是如果原本有 association 关系绑定的话就按 association 来处理,否则统一按返回单条非数组来处理
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯呐,也是一个办法,就是也是一个 breaking change,我明天去 poll 一下我这边用户们的意见 :-/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯呐,也是一个办法,就是也是一个 breaking change,我明天去 poll 一下我这边用户们的意见 :-/
其实也比较隐式。。join 的返回可能是数组可能是单条。返回的结果类型因为其他条件而变化了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哦对,我当时想到一个办法是加一个 joinMany(),后者返回数组,前者保持不变
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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() 方法的目的是用来编写临时的联表查询,期望结果一对一或者一对多,都是有可能的
efe2cf9
to
012ea6d
Compare
012ea6d
to
3369464
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
fix #417