/
model.ejs
58 lines (49 loc) · 1.72 KB
/
model.ejs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var <%= names.constructor.singular %> = function () {
this.defineProperties({
<% for (var i in properties) { -%>
<% 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});
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 %>);