-
Notifications
You must be signed in to change notification settings - Fork 6
/
Model.cfc
182 lines (112 loc) · 3.63 KB
/
Model.cfc
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
component accessors="true" {
/**
* @inject coldmvc
*/
property DAO;
property createdOn;
property createdBy;
property updatedOn;
property updatedBy;
public numeric function count() {
return DAO.count(this);
}
public numeric function countWhere(required struct parameters) {
return DAO.countWhere(this, arguments.parameters);
}
public any function createQuery(struct options) {
if (!structKeyExists(arguments, "options")) {
arguments.options = {};
}
return DAO.createQuery(this, arguments.options);
}
public void function delete(boolean flush="true") {
DAO.delete(this, arguments.flush);
}
public boolean function exists(string id) {
if (structKeyExists(arguments, "id")) {
return DAO.exists(this, arguments.id);
} else {
return DAO.exists(this);
}
}
public any function find(required string query, struct parameters, struct options) {
if (!structKeyExists(arguments, "parameters")) {
arguments.parameters = {};
}
if (!structKeyExists(arguments, "options")) {
arguments.options = {};
}
return DAO.find(this, arguments.query, arguments.parameters, arguments.options);
}
public array function findAll(required string query, struct parameters, struct options) {
if (!structKeyExists(arguments, "parameters")) {
arguments.parameters = {};
}
if (!structKeyExists(arguments, "options")) {
arguments.options = {};
}
return DAO.findAll(this, arguments.query, arguments.parameters, arguments.options);
}
public any function findWhere(required struct parameters, struct options) {
if (!structKeyExists(arguments, "options")) {
arguments.options = {};
}
return DAO.findWhere(this, parameters, options);
}
public array function findAllWhere(required struct parameters, struct options) {
if (!structKeyExists(arguments, "options")) {
arguments.options = {};
}
return DAO.findAllWhere(this, parameters, options);
}
public any function get(required any id, any data, string properties="") {
if (isStruct(arguments.id)) {
arguments.data = arguments.id;
if (structKeyExists(arguments.data, "id")) {
arguments.id = arguments.data.id;
} else {
arguments.id = "";
}
}
var model = DAO.get(this, arguments.id);
if (structKeyExists(arguments, "data")) {
model.populate(arguments.data, arguments.properties);
}
return model;
}
public array function getAll(required any ids, struct options) {
if (!structKeyExists(arguments, "options")) {
arguments.options = {};
}
return DAO.getAll(this, arguments.ids, arguments.options);
}
public array function list(struct options) {
if (!structKeyExists(arguments, "options")) {
arguments.options = {};
}
return DAO.list(this, arguments.options);
}
public any function new(any data, string properties="") {
var model = DAO.new(this);
if (structKeyExists(arguments, "data")) {
model.populate(arguments.data, arguments.properties);
}
return model;
}
public any function populate(required struct data, string properties="") {
return DAO.populate(this, arguments.data, arguments.properties);
}
public any function prop(required string property, any value) {
if (structKeyExists(arguments, "value")) {
return DAO.setProperty(this, arguments.property, arguments.value);
} else {
return DAO.getProperty(this, arguments.property);
}
}
public any function save(boolean flush="true") {
return DAO.save(this, arguments.flush);
}
public any function onMissingMethod(required string missingMethodName, required struct missingMethodArguments) {
return DAO.missingMethod(this, arguments.missingMethodName, arguments.missingMethodArguments);
}
}