不要怂,就是干,撸起袖子干!

Commit 96bc06cc by Sascha Depold

using the inflection library; replace them by npm later

1 parent e71addc8
...@@ -18,7 +18,7 @@ SequelizeHelper = { ...@@ -18,7 +18,7 @@ SequelizeHelper = {
}, },
asTableIdentifier: function(name) { asTableIdentifier: function(name) {
return name.toLowerCase().replace(/s$/, "") + "Id" return SequelizeHelper.Inflection.singularize(name.toLowerCase()) + "Id"
}, },
addPrefix: function(prefix, string) { addPrefix: function(prefix, string) {
...@@ -26,7 +26,7 @@ SequelizeHelper = { ...@@ -26,7 +26,7 @@ SequelizeHelper = {
}, },
asTableName: function(name) { asTableName: function(name) {
return name + "s" return SequelizeHelper.Inflection.pluralize(name)
}, },
asSqlDate: function(date) { asSqlDate: function(date) {
...@@ -171,5 +171,7 @@ SequelizeHelper = { ...@@ -171,5 +171,7 @@ SequelizeHelper = {
arr2.forEach(function(e) { result.push(e) }) arr2.forEach(function(e) { result.push(e) })
return result return result
} }
} },
Inflection: require(__dirname + "/../lib/inflection/inflection")
} }
\ No newline at end of file
...@@ -18,9 +18,14 @@ module.exports = { ...@@ -18,9 +18,14 @@ module.exports = {
}, },
'SQL: asTableIdentifier': function(assert) { 'SQL: asTableIdentifier': function(assert) {
assert.equal(h.SQL.asTableIdentifier('Users'), 'userId') assert.equal(h.SQL.asTableIdentifier('Users'), 'userId')
assert.equal(h.SQL.asTableIdentifier('Children'), 'childId')
assert.equal(h.SQL.asTableIdentifier('Children'), 'childId')
assert.equal(h.SQL.asTableIdentifier('Mice'), 'mouseId')
}, },
'SQL: asTableName': function(assert) { 'SQL: asTableName': function(assert) {
assert.equal(h.SQL.asTableName('User'), 'Users') assert.equal(h.SQL.asTableName('User'), 'Users')
assert.equal(h.SQL.asTableName('Child'), 'Children')
assert.equal(h.SQL.asTableName('Mouse'), 'Mice')
}, },
'SQL: asSqlDate': function(assert) { 'SQL: asSqlDate': function(assert) {
var d = new Date(Date.parse("Tue, 1 Jan 2000 00:00:00 GMT")) var d = new Date(Date.parse("Tue, 1 Jan 2000 00:00:00 GMT"))
...@@ -93,5 +98,8 @@ module.exports = { ...@@ -93,5 +98,8 @@ module.exports = {
assert.eql(h.Hash.merge(src, target), {a:1, b:3, c:3}) assert.eql(h.Hash.merge(src, target), {a:1, b:3, c:3})
assert.eql(h.Hash.merge(src, target, true), {a:1, b:2, c:3}) assert.eql(h.Hash.merge(src, target, true), {a:1, b:2, c:3})
},
'Inflection: should be available': function(assert) {
assert.isDefined(h.Inflection)
} }
} }
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!