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

Commit 2ed685be by Overlook Motel

getAssociation finds by alias if provided

1 parent 38de94a5
Showing with 7 additions and 11 deletions
...@@ -59,36 +59,32 @@ Mixin.hasMany = function(associatedDAOFactory, options) { ...@@ -59,36 +59,32 @@ Mixin.hasMany = function(associatedDAOFactory, options) {
return this return this
} }
Mixin.getAssociation = function(target) { Mixin.getAssociation = function(target, alias) {
var result = null
for (var associationName in this.associations) { for (var associationName in this.associations) {
if (this.associations.hasOwnProperty(associationName)) { if (this.associations.hasOwnProperty(associationName)) {
var association = this.associations[associationName] var association = this.associations[associationName]
if (!result && (association.target === target)) { if (association.target === target && (alias === undefined ? !association.isAliased : association.as === alias)) {
result = association return association
} }
} }
} }
return result return null
} }
Mixin.getAssociationByAlias = function(alias) { Mixin.getAssociationByAlias = function(alias) {
var result = null
for (var associationName in this.associations) { for (var associationName in this.associations) {
if (this.associations.hasOwnProperty(associationName)) { if (this.associations.hasOwnProperty(associationName)) {
var association = this.associations[associationName] var association = this.associations[associationName]
if (!result && (association.options.as === alias)) { if (association.as === alias) {
result = association return association
} }
} }
} }
return result return null
} }
/* 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!