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

Commit a698f66c by Sascha Depold

a getter for associations

1 parent 26c55c0e
Showing with 16 additions and 0 deletions
......@@ -12,12 +12,14 @@ Mixin.hasOne = function(associatedDAO, options) {
this.associations[association.associationAccessor] = association.injectAttributes()
return this
}
Mixin.belongsTo = function(associatedDAO, options) {
// the id is in this table
var association = new BelongsTo(this, associatedDAO, Utils._.extend((options||{}), this.options))
this.associations[association.associationAccessor] = association.injectAttributes()
return this
}
Mixin.hasMany = function(associatedDAO, options) {
// the id is in the foreign table or in a connecting table
var association = new HasMany(this, associatedDAO, Utils._.extend((options||{}), this.options))
......@@ -25,6 +27,20 @@ Mixin.hasMany = function(associatedDAO, options) {
return this
}
Mixin.getAssociation = function(target, options) {
var result = null
for (var associationName in this.associations) {
var association = this.associations[associationName]
if (!result && (association.target === target)) {
result = association
}
}
return result
}
/* example for instance methods:
Mixin.prototype.test = function() {
console.log('asd')
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!