Permalink
Browse files

Closes #230, Don't manually add the ID attribute into the model prope…

…rty definitions.

Also fixed a bug where doing something like `geddy scaffold users name:string:def id:string:def` would cause ID to be set twice in the object, instead of it just being the default(applied to any other property that was the default before then changing it back again after another default property existed).
  • Loading branch information...
1 parent cd8bfd7 commit bc02170657abb46d279d22145e7ced060ae5277b @larzconwell larzconwell committed Oct 15, 2012
Showing with 17 additions and 9 deletions.
  1. +11 −3 templates/Jakefile
  2. +3 −3 templates/resource/model.ejs
  3. +3 −3 templates/scaffold/model.ejs
View
@@ -240,10 +240,18 @@ namespace('gen', function () {
break;
}
- // Manage properties that deal with changing the default property
+ // Manage properties that deal with changing default properties
if (args === 'default') {
- // Reset old default to it's own property
- obj[obj['default'].name] = obj[obj['default'].name] || obj['default'];
+ // Reset old default property to it's own property, only if it's not
+ // already the default
+ if (name !== obj['default'].name) {
+ // If the new default item already exists then delete it
+ if (obj[name]) {
+ delete obj[name];
+ }
+
+ obj[obj['default'].name] = obj[obj['default'].name] || obj['default'];
+ }
// Add new default property
obj['default'] = {name: name, type: type};
@@ -2,22 +2,22 @@ var <%= names.constructor.singular %> = function () {
this.defineProperties({
<% for (var i in properties) { -%>
-<% if (i === 'default') { -%>
<% if (properties[i].name !== 'id') { -%>
+<% if (i === 'default') { -%>
<%= properties[i].name %>: {type: '<%= properties[i].type %>', required: true},
-<% } -%>
<% } else { -%>
<%= properties[i].name %>: {type: '<%= properties[i].type %>'},
<% } -%>
<% } -%>
+<% } -%>
});
<% for(var i in properties) { -%>
<% if(properties[i].name === 'id' && properties[i].type === 'int') { -%>
this.autoIncrementId = true;
+
<% } -%>
<% } -%>
-
/*
this.property('login', 'string', {required: true});
this.property('password', 'string', {required: true});
@@ -2,22 +2,22 @@ var <%= names.constructor.singular %> = function () {
this.defineProperties({
<% for (var i in properties) { -%>
-<% if (i === 'default') { -%>
<% if (properties[i].name !== 'id') { -%>
+<% if (i === 'default') { -%>
<%= properties[i].name %>: {type: '<%= properties[i].type %>', required: true},
-<% } -%>
<% } else { -%>
<%= properties[i].name %>: {type: '<%= properties[i].type %>'},
<% } -%>
<% } -%>
+<% } -%>
});
<% for(var i in properties) { -%>
<% if(properties[i].name === 'id' && properties[i].type === 'int') { -%>
this.autoIncrementId = true;
+
<% } -%>
<% } -%>
-
/*
this.property('login', 'string', {required: true});
this.property('password', 'string', {required: true});

0 comments on commit bc02170

Please sign in to comment.