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

Commit 38de94a5 by Overlook Motel

make consistent use of as when creating associations and flag aliases

1 parent c0092e7e
......@@ -17,8 +17,10 @@ module.exports = (function() {
this.options.foreignKey = Utils._.underscoredIf(Utils.singularize(this.source.tableName, this.source.options.language) + "Id", this.source.options.underscored)
}
if (!this.as) {
this.as = this.options.as = Utils.singularize(this.target.tableName, this.target.options.language)
if (this.as) {
this.isAliased = true
} else {
this.as = Utils.singularize(this.target.tableName, this.target.options.language)
}
this.associationAccessor = this.isSelfAssociation
......
......@@ -21,9 +21,10 @@ module.exports = (function() {
this.isMultiAssociation = true
this.isSelfAssociation = this.source === this.target
this.doubleLinked = false
this.as = this.options.as
this.combinedTableName = Utils.combineTableNames(
this.source.tableName,
this.isSelfAssociation ? (this.options.as || this.target.tableName) : this.target.tableName
this.isSelfAssociation ? (this.as || this.target.tableName) : this.target.tableName
)
/*
......@@ -48,7 +49,7 @@ module.exports = (function() {
* Determine associationAccessor, especially for include options to identify the correct model
*/
this.associationAccessor = this.options.as
this.associationAccessor = this.as
if (!this.associationAccessor && (typeof this.through === "string" || Object(this.through) === this.through)) {
this.associationAccessor = this.through.tableName || this.through
}
......@@ -112,16 +113,20 @@ module.exports = (function() {
this.options.tableName = this.combinedName = (this.through === Object(this.through) ? this.through.tableName : this.through)
var as = (this.options.as || Utils.pluralize(this.target.tableName, this.target.options.language))
if (this.as) {
this.isAliased = true
} else {
this.as = Utils.pluralize(this.target.tableName, this.target.options.language)
}
this.accessors = {
get: Utils._.camelize('get_' + as),
set: Utils._.camelize('set_' + as),
add: Utils._.camelize(Utils.singularize('add_' + as, this.target.options.language)),
create: Utils._.camelize(Utils.singularize('create_' + as, this.target.options.language)),
remove: Utils._.camelize(Utils.singularize('remove_' + as, this.target.options.language)),
hasSingle: Utils._.camelize(Utils.singularize('has_' + as, this.target.options.language)),
hasAll: Utils._.camelize('has_' + as)
get: Utils._.camelize('get_' + this.as),
set: Utils._.camelize('set_' + this.as),
add: Utils._.camelize(Utils.singularize('add_' + this.as, this.target.options.language)),
create: Utils._.camelize(Utils.singularize('create_' + this.as, this.target.options.language)),
remove: Utils._.camelize(Utils.singularize('remove_' + this.as, this.target.options.language)),
hasSingle: Utils._.camelize(Utils.singularize('has_' + this.as, this.target.options.language)),
hasAll: Utils._.camelize('has_' + this.as)
}
}
......
......@@ -11,25 +11,28 @@ module.exports = (function() {
this.options = options
this.isSingleAssociation = true
this.isSelfAssociation = (this.source.tableName == this.target.tableName)
this.as = this.options.as
if (this.isSelfAssociation && !this.options.foreignKey && !!this.options.as) {
this.options.foreignKey = Utils._.underscoredIf(Utils.singularize(this.options.as, this.target.options.language) + "Id", this.options.underscored)
if (this.isSelfAssociation && !this.options.foreignKey && !!this.as) {
this.options.foreignKey = Utils._.underscoredIf(Utils.singularize(this.as, this.target.options.language) + "Id", this.options.underscored)
}
if (!this.options.as) {
this.options.as = Utils.singularize(this.target.tableName, this.target.options.language)
if (this.as) {
this.isAliased = true
} else {
this.as = Utils.singularize(this.target.tableName, this.target.options.language)
}
this.associationAccessor = this.isSelfAssociation
? Utils.combineTableNames(this.target.tableName, this.options.as)
: this.options.as
? Utils.combineTableNames(this.target.tableName, this.as)
: this.as
this.options.useHooks = options.useHooks
this.accessors = {
get: Utils._.camelize('get_' + this.options.as),
set: Utils._.camelize('set_' + this.options.as),
create: Utils._.camelize('create_' + this.options.as)
get: Utils._.camelize('get_' + this.as),
set: Utils._.camelize('set_' + this.as),
create: Utils._.camelize('create_' + this.as)
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!