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

Commit 28ac7564 by Sascha Depold

chainable associations

1 parent 5a73894c
Showing with 5 additions and 1 deletions
# v1.3.0 # # v1.3.0 #
- [REFACTORING] Model#all is now a function and not a getter. - [REFACTORING] Model#all is now a function and not a getter.
- [REFACTORING] Renamed ModelDefinition to ModelFactory
- [FEATURE] Association definition is chainable: Person.hasOne(House).hasMany(Address)
# v1.2.1 # # v1.2.1 #
- [REFACTORING] renamed the global options for sync, query and define on sequelize; before: options.queryOptions; now: options.query - [REFACTORING] renamed the global options for sync, query and define on sequelize; before: options.queryOptions; now: options.query
......
...@@ -8,18 +8,21 @@ Mixin.hasOne = function(associatedModel, options) { ...@@ -8,18 +8,21 @@ Mixin.hasOne = function(associatedModel, options) {
var HasOne = require('./has-one') var HasOne = require('./has-one')
var association = new HasOne(this, associatedModel, Utils._.extend((options||{}), this.options)) var association = new HasOne(this, associatedModel, Utils._.extend((options||{}), this.options))
this.associations[association.associationAccessor] = association.injectAttributes() this.associations[association.associationAccessor] = association.injectAttributes()
return this
} }
Mixin.belongsTo = function(associatedModel, options) { Mixin.belongsTo = function(associatedModel, options) {
// the id is in this table // the id is in this table
var BelongsTo = require("./belongs-to") var BelongsTo = require("./belongs-to")
var association = new BelongsTo(this, associatedModel, Utils._.extend((options||{}), this.options)) var association = new BelongsTo(this, associatedModel, Utils._.extend((options||{}), this.options))
this.associations[association.associationAccessor] = association.injectAttributes() this.associations[association.associationAccessor] = association.injectAttributes()
return this
} }
Mixin.hasMany = function(associatedModel, options) { Mixin.hasMany = function(associatedModel, options) {
// the id is in the foreign table or in a connecting table // the id is in the foreign table or in a connecting table
var HasMany = require("./has-many") var HasMany = require("./has-many")
var association = new HasMany(this, associatedModel, Utils._.extend((options||{}), this.options)) var association = new HasMany(this, associatedModel, Utils._.extend((options||{}), this.options))
this.associations[association.associationAccessor] = association.injectAttributes() this.associations[association.associationAccessor] = association.injectAttributes()
return this
} }
/* example for instance methods: /* example for instance methods:
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!