waterline-schema
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -47,3 +47,3 @@ | ||
var modelName = attributes[attribute].model.toLowerCase(); | ||
var modelName = attributes[attribute].model; | ||
var primaryKey = this.findPrimaryKey(modelName); | ||
@@ -56,3 +56,3 @@ var columnName = this.buildColumnName(attribute, attributes[attribute]); | ||
references: modelName, | ||
on: primaryKey.name.toLowerCase() | ||
on: primaryKey.name | ||
}; | ||
@@ -113,4 +113,4 @@ | ||
ForeignKeys.prototype.buildColumnName = function(key, attribute) { | ||
if(hasOwnProperty(attribute, 'columnName')) return attribute.columnName.toLowerCase(); | ||
return key.toLowerCase(); | ||
if(hasOwnProperty(attribute, 'columnName')) return attribute.columnName; | ||
return key; | ||
}; |
@@ -78,3 +78,3 @@ | ||
var child = this.collections[attr.collection.toLowerCase()]; | ||
var child = this.collections[attr.collection]; | ||
@@ -93,4 +93,4 @@ // Ensure the `via` exists on the child. | ||
column_one: { | ||
collection: collection.toLowerCase(), | ||
attribute: attribute.toLowerCase(), | ||
collection: collection, | ||
attribute: attribute, | ||
via: attr.via | ||
@@ -100,4 +100,4 @@ }, | ||
column_two: { | ||
collection: attr.collection.toLowerCase(), | ||
attribute: attr.via.toLowerCase(), | ||
collection: attr.collection, | ||
attribute: attr.via, | ||
via: attribute | ||
@@ -251,3 +251,3 @@ } | ||
var primaryKey = this.findPrimaryKey(column_one.collection); | ||
var columnName = (column_one.collection + '_' + column_one.attribute).toLowerCase(); | ||
var columnName = (column_one.collection + '_' + column_one.attribute); | ||
var viaName = column_two.collection + '_' + column_one.via; | ||
@@ -259,6 +259,6 @@ | ||
foreignKey: true, | ||
references: column_one.collection.toLowerCase(), | ||
on: primaryKey.name.toLowerCase(), | ||
references: column_one.collection, | ||
on: primaryKey.name, | ||
via: viaName, | ||
groupKey: column_one.collection.toLowerCase() | ||
groupKey: column_one.collection | ||
}; | ||
@@ -278,16 +278,4 @@ }; | ||
tables.forEach(function(table) { | ||
var add = true; | ||
var table1 = table.tables[0]; | ||
var table2 = table.tables[1]; | ||
for(var key in self.tables) { | ||
var join = self.tables[key]; | ||
if(join.tables.indexOf(table1) < 0) continue; | ||
if(join.tables.indexOf(table2) < 0) continue; | ||
add = false; | ||
} | ||
if(add) self.tables[table.identity] = table; | ||
if(hasOwnProperty(self.tables, table.identity)) return; | ||
self.tables[table.identity] = table; | ||
}); | ||
@@ -355,5 +343,9 @@ }; | ||
var link = attributes[attribute].collection; | ||
var joined = this.findJoinTable(collection, link); | ||
var attr = attributes[attribute]; | ||
var parent = collection; | ||
var child = attr.collection; | ||
var via = attr.via; | ||
var joined = this.findJoinTable(parent, child, via); | ||
if(!joined.join) continue; | ||
@@ -385,3 +377,3 @@ | ||
var linkedCollection = attributes[attribute].through.toLowerCase(); | ||
var linkedCollection = attributes[attribute].through; | ||
this.collections[linkedCollection].junctionTable = true; | ||
@@ -395,3 +387,3 @@ | ||
var reference = this.findReference(collection, linkedCollection); | ||
attributes[attribute].on = reference.toLowerCase(); | ||
attributes[attribute].on = reference; | ||
@@ -432,2 +424,3 @@ delete attributes[attribute].through; | ||
* @param {String} child | ||
* @param {String} via | ||
* @return {Object} | ||
@@ -437,3 +430,3 @@ * @api private | ||
JoinTables.prototype.findJoinTable = function(parent, child) { | ||
JoinTables.prototype.findJoinTable = function(parent, child, via) { | ||
var join = false, | ||
@@ -448,4 +441,9 @@ tableCollection; | ||
var column = child + '_' + via; | ||
if(!hasOwnProperty(this.tables[table].attributes, column)) continue; | ||
join = true; | ||
tableCollection = this.tables[table]; | ||
break; | ||
} | ||
@@ -452,0 +450,0 @@ |
@@ -53,3 +53,3 @@ | ||
attributes[attribute].collection = attributes[attribute].collection.toLowerCase(); | ||
attributes[attribute].collection = attributes[attribute].collection; | ||
@@ -62,3 +62,3 @@ // Check For HasMany Through | ||
attributes[attribute].references = attributes[attribute].through; | ||
attributes[attribute].on = reference.toLowerCase(); | ||
attributes[attribute].on = reference; | ||
delete attributes[attribute].through; | ||
@@ -74,3 +74,3 @@ | ||
attributes[attribute].references = attributes[attribute].collection; | ||
attributes[attribute].on = reference.toLowerCase(); | ||
attributes[attribute].on = reference; | ||
} | ||
@@ -77,0 +77,0 @@ }; |
{ | ||
"name": "waterline-schema", | ||
"description": "The core schema builder used in the Waterline ORM.", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"contributors": [ | ||
@@ -6,0 +6,0 @@ { |
46372
1276