0

ノード開発者で dresende/node-orm2 ORM を使用しています。しかし、いくつかの LEFT / RIGHT 結合を行う必要がありますが、ドキュメントで方法が見つかりません。複数の結合を作成しようとしているときにも問題が発生しています。

このコード:

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);
});

次のクエリを生成します。

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

ありがとう、そして私の下手な英語でごめんなさい。

4

1 に答える 1

0

ORM の秘訣は、関係を機能させるためのコマンドではなく、関係を想像することです。ORM2 には hasMany アソシエーションがあります。私はそこから始めます。ドキュメントから:

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

于 2016-04-15T18:52:15.250 に答える