Skip to content

Commit

Permalink
getAssociation finds by alias if provided
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Feb 9, 2014
1 parent 38de94a commit 2ed685b
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/associations/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,36 +59,32 @@ Mixin.hasMany = function(associatedDAOFactory, options) {
return this
}

Mixin.getAssociation = function(target) {
var result = null

Mixin.getAssociation = function(target, alias) {
for (var associationName in this.associations) {
if (this.associations.hasOwnProperty(associationName)) {
var association = this.associations[associationName]

if (!result && (association.target === target)) {
result = association
if (association.target === target && (alias === undefined ? !association.isAliased : association.as === alias)) {
return association
}
}
}

return result
return null
}

Mixin.getAssociationByAlias = function(alias) {
var result = null

for (var associationName in this.associations) {
if (this.associations.hasOwnProperty(associationName)) {
var association = this.associations[associationName]

if (!result && (association.options.as === alias)) {
result = association
if (association.as === alias) {
return association
}
}
}

return result
return null
}

/* example for instance methods:
Expand Down

0 comments on commit 2ed685b

Please sign in to comment.