Fix options for hasManyThrough doesn't apply
Signed-off-by: Clark Wang <clark.wangs@gmail.com>
This commit is contained in:
parent
f9a26bcb28
commit
4b70f2498f
|
@ -417,7 +417,7 @@ DataSource.prototype.defineRelations = function (modelClass, relations) {
|
||||||
throughModel.once('dataAccessConfigured', function (model) {
|
throughModel.once('dataAccessConfigured', function (model) {
|
||||||
if (isModelDataSourceAttached(targetModel)) {
|
if (isModelDataSourceAttached(targetModel)) {
|
||||||
// The target model is resolved
|
// The target model is resolved
|
||||||
var params = traverse(relations).clone();
|
var params = traverse(relation).clone();
|
||||||
params.as = name;
|
params.as = name;
|
||||||
params.model = targetModel;
|
params.model = targetModel;
|
||||||
params.through = model;
|
params.through = model;
|
||||||
|
|
|
@ -1110,6 +1110,27 @@ describe('Load models with relations', function () {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle hasMany through options', function (done) {
|
||||||
|
var ds = new DataSource('memory');
|
||||||
|
var Physician = ds.createModel('Physician', {
|
||||||
|
name: String
|
||||||
|
}, {relations: {patients: {model: 'Patient', type: 'hasMany', foreignKey: 'leftId', through: 'Appointment'}}});
|
||||||
|
|
||||||
|
var Patient = ds.createModel('Patient', {
|
||||||
|
name: String
|
||||||
|
}, {relations: {physicians: {model: 'Physician', type: 'hasMany', foreignKey: 'rightId', through: 'Appointment'}}});
|
||||||
|
|
||||||
|
var Appointment = ds.createModel('Appointment', {
|
||||||
|
physicianId: Number,
|
||||||
|
patientId: Number,
|
||||||
|
appointmentDate: Date
|
||||||
|
}, {relations: {patient: {type: 'belongsTo', model: 'Patient'}, physician: {type: 'belongsTo', model: 'Physician'}}});
|
||||||
|
|
||||||
|
assert(Physician.relations['patients'].keyTo === 'leftId');
|
||||||
|
assert(Patient.relations['physicians'].keyTo === 'rightId');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
it('should set up relations after attach', function (done) {
|
it('should set up relations after attach', function (done) {
|
||||||
var ds = new DataSource('memory');
|
var ds = new DataSource('memory');
|
||||||
var modelBuilder = new ModelBuilder();
|
var modelBuilder = new ModelBuilder();
|
||||||
|
|
Loading…
Reference in New Issue