Enable DL definition of embedsMany + referencesMany
This commit is contained in:
parent
6ea6f19752
commit
a243d05880
|
@ -3,6 +3,7 @@
|
|||
*/
|
||||
var ModelBuilder = require('./model-builder.js').ModelBuilder;
|
||||
var ModelDefinition = require('./model-definition.js');
|
||||
var RelationDefinition = require('./relation-definition.js');
|
||||
var jutil = require('./jutil');
|
||||
var utils = require('./utils');
|
||||
var ModelBaseClass = require('./model.js');
|
||||
|
@ -364,7 +365,7 @@ function isModelClass(cls) {
|
|||
return cls.prototype instanceof ModelBaseClass;
|
||||
}
|
||||
|
||||
DataSource.relationTypes = ['belongsTo', 'hasMany', 'hasAndBelongsToMany', 'hasOne'];
|
||||
DataSource.relationTypes = Object.keys(RelationDefinition.RelationTypes);
|
||||
|
||||
function isModelDataSourceAttached(model) {
|
||||
return model && (!model.settings.unresolved) && (model.dataSource instanceof DataSource);
|
||||
|
|
|
@ -903,6 +903,26 @@ describe('Load models with relations', function () {
|
|||
assert(Post.relations['user']);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should set up referencesMany relations', function (done) {
|
||||
var ds = new DataSource('memory');
|
||||
|
||||
var Post = ds.define('Post', {userId: Number, content: String});
|
||||
var User = ds.define('User', {name: String}, {relations: {posts: {type: 'referencesMany', model: 'Post'}}});
|
||||
|
||||
assert(User.relations['posts']);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should set up embedsMany relations', function (done) {
|
||||
var ds = new DataSource('memory');
|
||||
|
||||
var Post = ds.define('Post', {userId: Number, content: String});
|
||||
var User = ds.define('User', {name: String}, {relations: {posts: {type: 'embedsMany', model: 'Post'}}});
|
||||
|
||||
assert(User.relations['posts']);
|
||||
done();
|
||||
});
|
||||
|
||||
it('should set up foreign key with the correct type', function (done) {
|
||||
var ds = new DataSource('memory');
|
||||
|
|
Loading…
Reference in New Issue