Permalink
Fetching contributors…
Cannot retrieve contributors at this time
67 lines (55 sloc) 1.83 KB
var <%= names.constructor.singular %> = function () {
<%
var propertyOutput = [],
currentProperty;
for (var i in properties) {
if (properties[i].name && properties[i].name !== "id") {
currentProperty = properties[i].name + ": {type: '" + properties[i].type + "'";
if (i === "default") {
currentProperty += ", required: true";
}
currentProperty += "}";
propertyOutput.push(currentProperty);
}
}
%>
this.defineProperties({
<%- propertyOutput.join(",\n "); %>
});
<% 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});
this.property('lastName', 'string');
this.property('firstName', 'string');
this.validatesPresent('login');
this.validatesFormat('login', /[a-z]+/, {message: 'Subdivisions!'});
this.validatesLength('login', {min: 3});
// Use with the name of the other parameter to compare with
this.validatesConfirmed('password', 'confirmPassword');
// Use with any function that returns a Boolean
this.validatesWithFunction('password', function (s) {
return s.length > 0;
});
// Can define methods for instances like this
this.someMethod = function () {
// Do some stuff
};
*/
};
/*
// Can also define them on the prototype
<%= names.constructor.singular %>.prototype.someOtherMethod = function () {
// Do some other stuff
};
// Can also define static methods and properties
<%= names.constructor.singular %>.someStaticMethod = function () {
// Do some other stuff
};
<%= names.constructor.singular %>.someStaticProperty = 'YYZ';
*/
<%= names.constructor.singular %> = geddy.model.register('<%= names.constructor.singular %>', <%= names.constructor.singular %>);