首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >node-orm2上的左/右连接

node-orm2上的左/右连接
EN

Stack Overflow用户
提问于 2015-10-11 05:34:03
回答 1查看 156关注 0票数 0

我在我的node devs中使用/node-orm2 ORM。但是我需要进行一些左/右连接,但是我在文档中找不到方法。在尝试进行多个连接时,我也遇到了问题。

这段代码:

代码语言:javascript
复制
crModel.hasOne ('client', cliModel, {

    field:  'client_id'
});

crModel.hasOne ('office', boModel, {

    field:  'bo_id'
});

crModel.findByClient ({}).findByOffice ({}).find ({

    client_id:  1,
    bo_id:      1
}, function () {

    console.log (arguments);
});

生成此查询:

代码语言:javascript
复制
SELECT `t1`.`cr_id`, `t1`.`cr_datetime`, `t1`.`credit_id`, `t1`.`gs_id`, `t1`.`cellphone_id`, `t1`.`bo_id`, `t1`.`client_id` FROM `CreditRequests` `t1` JOIN `BranchOffices` `t2` ON `t2`.`bo_id` = `t1`.`bo_id` WHERE `t1`.`client_id` = 1 AND `t1`.`bo_id` = 1

谢谢,很抱歉我的英语很差。

EN

回答 1

Stack Overflow用户

发布于 2016-04-16 02:52:15

ORM的诀窍是设想关系,而不是让它工作的命令。有了ORM2,就有了hasMany关联--我就从这里开始吧。从文档中:

代码语言:javascript
复制
patient.getDoctors(function..)           // List of doctors
patient.addDoctors(docs, function...)    // Adds entries to join table
patient.setDoctors(docs, function...)    // Removes existing entries in join table, adds new ones
patient.hasDoctors(docs, function...)    // Checks if patient is associated to specified doctors
patient.removeDoctors(docs, function...) // Removes specified doctors from join table

doctor.getPatients(function..)
etc...

// You can also do:
patient.doctors = [doc1, doc2];
patient.save(...)

https://github.com/dresende/node-orm2

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33059191

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档