Allow to add connection with through data for HasManyThrough relation
Signed-off-by: Clark Wang <clark.wangs@gmail.com>
This commit is contained in:
parent
7698f0f08b
commit
565b85555c
|
@ -919,13 +919,16 @@ HasManyThrough.prototype.create = function create(data, done) {
|
||||||
* Add the target model instance to the 'hasMany' relation
|
* Add the target model instance to the 'hasMany' relation
|
||||||
* @param {Object|ID} acInst The actual instance or id value
|
* @param {Object|ID} acInst The actual instance or id value
|
||||||
*/
|
*/
|
||||||
HasManyThrough.prototype.add = function (acInst, done) {
|
HasManyThrough.prototype.add = function (acInst, data, done) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var definition = this.definition;
|
var definition = this.definition;
|
||||||
var modelThrough = definition.modelThrough;
|
var modelThrough = definition.modelThrough;
|
||||||
var pk1 = definition.keyFrom;
|
var pk1 = definition.keyFrom;
|
||||||
|
|
||||||
var data = {};
|
if (typeof data === 'function') {
|
||||||
|
done = data;
|
||||||
|
data = {};
|
||||||
|
}
|
||||||
var query = {};
|
var query = {};
|
||||||
|
|
||||||
// The primary key for the target model
|
// The primary key for the target model
|
||||||
|
|
|
@ -433,6 +433,24 @@ describe('relations', function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should allow to add connection with through data', function (done) {
|
||||||
|
Physician.create({name: 'ph1'}, function (e, physician) {
|
||||||
|
Patient.create({name: 'pa1'}, function (e, patient) {
|
||||||
|
var now = Date.now();
|
||||||
|
physician.patients.add(patient, { date: new Date(now) }, function (e, app) {
|
||||||
|
should.not.exist(e);
|
||||||
|
should.exist(app);
|
||||||
|
app.should.be.an.instanceOf(Appointment);
|
||||||
|
app.physicianId.should.equal(physician.id);
|
||||||
|
app.patientId.should.equal(patient.id);
|
||||||
|
app.patientId.should.equal(patient.id);
|
||||||
|
app.date.getTime().should.equal(now);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should allow to remove connection with instance', function (done) {
|
it('should allow to remove connection with instance', function (done) {
|
||||||
var id;
|
var id;
|
||||||
Physician.create(function (err, physician) {
|
Physician.create(function (err, physician) {
|
||||||
|
|
Loading…
Reference in New Issue