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

修复数据库返回字段只有下划线(aa_bb_cc)方式的问题 #524

Merged
merged 5 commits into from
Dec 15, 2016

Conversation

ruanzhijun
Copy link
Contributor

原有的老项目用的是java,数据库定义的字段为下划线(aa_bb_cc)方式,返回给客户端的字段为驼峰式。现在新的需求用thinkjs实现,我们使用thinkjs是直接由model层获取得数据然后返回,由于数据库定义的是下划线,所以node实现的接口与java返回的数据格式不一致。为了解决这个问题,我在config/db.js加了一个配置camel_case选项,修改model/base.js的parseOptions方法和parseData方法,使其支持返回的字段是下划线( snakeCase )or驼峰式( camelCase )。

@welefen
Copy link
Member

welefen commented Dec 13, 2016

这个可以通过 afterSelect afterFind 之类的切面方法来实现

@welefen
Copy link
Member

welefen commented Dec 13, 2016

@ruanzhijun
Copy link
Contributor Author

我知道,但是如果数据量大的情况下,遍历逐条数据修改的性能还不如直接修改sql来得好。

@ckken
Copy link
Contributor

ckken commented Dec 13, 2016

你好,切面的话只能后置解决问题,遇到多分表的情况还是解决不了,例如用户表分几十张,然后涉及到跨库,不可能建几十个model 来解决,这是我们团队经过两天研究得到最优的解决方案!

@welefen
Copy link
Member

welefen commented Dec 14, 2016

OK,处理下 eslint 检测报错,执行 eslint src/ 可以看到。

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.5%) to 92.374% when pulling 4140a34 on ruanzhijun:master into 0a72167 on 75team:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 92.235% when pulling 58ffa91 on ruanzhijun:master into 0a72167 on 75team:master.

@welefen welefen merged commit 2d848e7 into thinkjs:master Dec 15, 2016
@CyberNika
Copy link

CyberNika commented Feb 14, 2017

希望测试下关联模型,我在使用时打开 camel_case 后发现关联模型获取不到关联数据。当关联模型为 HAS_MANY 时,SQL 解析还会出错。

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.

None yet

5 participants