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

Commit 63d2aa6a by Sascha Depold

renamed assoc getters to get*

1 parent cb72b05e
...@@ -163,7 +163,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o ...@@ -163,7 +163,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
type: 'hasOne' type: 'hasOne'
}) })
table.prototype[assocName] = function(callback) { table.prototype[Sequelize.Helper.SQL.addPrefix('get', assocName)] = function(callback) {
var whereConditions = {} var whereConditions = {}
whereConditions[table.identifier] = this.id whereConditions[table.identifier] = this.id
_table.find(whereConditions, callback) _table.find(whereConditions, callback)
...@@ -172,7 +172,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o ...@@ -172,7 +172,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
table.prototype[Sequelize.Helper.SQL.addPrefix('set', assocName)] = function(object, callback) { table.prototype[Sequelize.Helper.SQL.addPrefix('set', assocName)] = function(object, callback) {
var self = this var self = this
this[assocName](function(currentAssociation) { this[Sequelize.Helper.SQL.addPrefix('get', assocName)](function(currentAssociation) {
var attr = {} var attr = {}
if(currentAssociation == null) { if(currentAssociation == null) {
attr[table.identifier] = self.id attr[table.identifier] = self.id
...@@ -200,7 +200,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o ...@@ -200,7 +200,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
type: 'belongsTo' type: 'belongsTo'
}) })
table.prototype[assocName] = function(callback) { table.prototype[Sequelize.Helper.SQL.addPrefix('get', assocName)] = function(callback) {
if((this[_table.identifier] == null)||(isNaN(this[_table.identifier]))) if((this[_table.identifier] == null)||(isNaN(this[_table.identifier])))
callback([]) callback([])
else else
...@@ -211,7 +211,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o ...@@ -211,7 +211,7 @@ exports.SequelizeTable = function(Sequelize, sequelize, tableName, attributes, o
var attr = {}; attr[object.table.identifier] = object.id var attr = {}; attr[object.table.identifier] = object.id
var self = this var self = this
this.updateAttributes(attr, function() { this.updateAttributes(attr, function() {
self[assocName](callback) self[Sequelize.Helper.SQL.addPrefix('get', assocName)](callback)
}) })
} }
......
...@@ -134,7 +134,7 @@ module.exports = { ...@@ -134,7 +134,7 @@ module.exports = {
'hasMany': function(assert) { 'hasMany': function(assert) {
var HasManyBlubb = s.define('HasManyBlubb', {}) var HasManyBlubb = s.define('HasManyBlubb', {})
Day.hasMany('HasManyBlubbs', HasManyBlubb) Day.hasMany('HasManyBlubbs', HasManyBlubb)
assert.isDefined(new Day({name:''}).HasManyBlubbs) assert.isDefined(new Day({name:''}).getHasManyBlubbs)
}, },
'hasMany: set association': function(assert, beforeExit) { 'hasMany: set association': function(assert, beforeExit) {
var assoc = null var assoc = null
...@@ -169,7 +169,7 @@ module.exports = { ...@@ -169,7 +169,7 @@ module.exports = {
var Day = s.define('Day2', { name: Sequelize.TEXT }) var Day = s.define('Day2', { name: Sequelize.TEXT })
var HasOneBlubb = s.define('HasOneBlubb', {}) var HasOneBlubb = s.define('HasOneBlubb', {})
Day.hasOne('HasOneBlubb', HasOneBlubb) Day.hasOne('HasOneBlubb', HasOneBlubb)
assert.isDefined(new Day({name:''}).HasOneBlubb) assert.isDefined(new Day({name:''}).getHasOneBlubb)
}, },
'hasOne set association': function(assert, beforeExit) { 'hasOne set association': function(assert, beforeExit) {
var s2 = new Sequelize('sequelize_test', 'test', 'test', {disableLogging: true}) var s2 = new Sequelize('sequelize_test', 'test', 'test', {disableLogging: true})
...@@ -197,7 +197,7 @@ module.exports = { ...@@ -197,7 +197,7 @@ module.exports = {
'belongsTo': function(assert) { 'belongsTo': function(assert) {
var BelongsToBlubb = s.define('BelongsToBlubb', {}) var BelongsToBlubb = s.define('BelongsToBlubb', {})
Day.belongsTo('BelongsToBlubb', BelongsToBlubb) Day.belongsTo('BelongsToBlubb', BelongsToBlubb)
assert.isDefined(new Day({name:''}).BelongsToBlubb) assert.isDefined(new Day({name:''}).getBelongsToBlubb)
}, },
'belongsTo: set association': function(assert, beforeExit) { 'belongsTo: set association': function(assert, beforeExit) {
var s2 = new Sequelize('sequelize_test', 'test', 'test', {disableLogging: true}) var s2 = new Sequelize('sequelize_test', 'test', 'test', {disableLogging: true})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!