diff --git a/lib/scope.js b/lib/scope.js index de6cfb8a..6b4dafb1 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -168,7 +168,7 @@ function defineScope(cls, targetClass, name, params, methods, options) { f._targetClass = targetModel.modelName; if (f._scope.collect) { - f._targetClass = i8n.capitalize(f._scope.collect); + f._targetClass = i8n.camelize(f._scope.collect); } f.build = build; diff --git a/test/relations.test.js b/test/relations.test.js index c9aa25fb..12e78d68 100644 --- a/test/relations.test.js +++ b/test/relations.test.js @@ -1624,15 +1624,15 @@ describe('relations', function () { }); describe('hasAndBelongsToMany', function () { - var Article, Tag, ArticleTag; + var Article, TagName, ArticleTag; it('can be declared', function (done) { Article = db.define('Article', {title: String}); - Tag = db.define('Tag', {name: String}); - Article.hasAndBelongsToMany('tags'); - ArticleTag = db.models.ArticleTag; + TagName = db.define('TagName', {name: String}); + Article.hasAndBelongsToMany('tagNames'); + ArticleTag = db.models.ArticleTagName; db.automigrate(function () { Article.destroyAll(function () { - Tag.destroyAll(function () { + TagName.destroyAll(function () { ArticleTag.destroyAll(done) }); }); @@ -1641,11 +1641,11 @@ describe('relations', function () { it('should allow to create instances on scope', function (done) { Article.create(function (e, article) { - article.tags.create({name: 'popular'}, function (e, t) { - t.should.be.an.instanceOf(Tag); + article.tagNames.create({name: 'popular'}, function (e, t) { + t.should.be.an.instanceOf(TagName); ArticleTag.findOne(function (e, at) { should.exist(at); - at.tagId.toString().should.equal(t.id.toString()); + at.tagNameId.toString().should.equal(t.id.toString()); at.articleId.toString().should.equal(article.id.toString()); done(); }); @@ -1655,7 +1655,7 @@ describe('relations', function () { it('should allow to fetch scoped instances', function (done) { Article.findOne(function (e, article) { - article.tags(function (e, tags) { + article.tagNames(function (e, tags) { should.not.exist(e); should.exist(tags); @@ -1668,12 +1668,12 @@ describe('relations', function () { it('should allow to add connection with instance', function (done) { Article.findOne(function (e, article) { - Tag.create({name: 'awesome'}, function (e, tag) { - article.tags.add(tag, function (e, at) { + TagName.create({name: 'awesome'}, function (e, tag) { + article.tagNames.add(tag, function (e, at) { should.not.exist(e); should.exist(at); at.should.be.an.instanceOf(ArticleTag); - at.tagId.should.equal(tag.id); + at.tagNameId.should.equal(tag.id); at.articleId.should.equal(article.id); done(); }); @@ -1683,12 +1683,12 @@ describe('relations', function () { it('should allow to remove connection with instance', function (done) { Article.findOne(function (e, article) { - article.tags(function (e, tags) { + article.tagNames(function (e, tags) { var len = tags.length; tags.should.not.be.empty; - article.tags.remove(tags[0], function (e) { + article.tagNames.remove(tags[0], function (e) { should.not.exist(e); - article.tags(true, function (e, tags) { + article.tagNames(true, function (e, tags) { tags.should.have.lengthOf(len - 1); done(); }); @@ -1698,7 +1698,7 @@ describe('relations', function () { }); it('should set targetClass on scope property', function() { - should.equal(Article.prototype.tags._targetClass, 'Tag'); + should.equal(Article.prototype.tagNames._targetClass, 'TagName'); }); });