forked from tdm00/cfwheels-dbmigrate-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForeignKeyDefinition.cfc
More file actions
executable file
·42 lines (37 loc) · 1.96 KB
/
ForeignKeyDefinition.cfc
File metadata and controls
executable file
·42 lines (37 loc) · 1.96 KB
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
<cfcomponent extends="Base">
<cffunction name="init" returntype="ForeignKeyDefinition" access="public">
<cfargument name="adapter" type="any" required="yes" hint="database adapter">
<cfargument name="table" type="string" required="yes" hint="table name">
<cfargument name="referenceTable" type="string" required="yes" hint="referenced table name">
<cfargument name="column" type="string" required="yes" hint="column name">
<cfargument name="referenceColumn" type="string" required="yes" hint="referenced column name">
<cfargument name="onUpdate" type="string" required="false" default="" hint="how you want the constraint to act on update. possible values include `none`, `null`, or `cascade` which can also be set to `true`.">
<cfargument name="onDelete" type="string" required="false" default="" hint="how you want the constraint to act on delete. possible values include `none`, `null`, or `cascade` which can also be set to `true`.">
<cfscript>
var loc = {};
loc.args = "adapter,table,referenceTable,column,referenceColumn,onUpdate,onDelete";
loc.iEnd = ListLen(loc.args);
for (loc.i=1; loc.i <= loc.iEnd; loc.i++) {
loc.argumentName = ListGetAt(loc.args,loc.i);
if(StructKeyExists(arguments,loc.argumentName)) {
this[loc.argumentName] = arguments[loc.argumentName];
}
}
this.name = "FK_#LCase(this.table)#_#LCase(this.referenceTable)#";
</cfscript>
<cfreturn this>
</cffunction>
<cffunction name="toSQL" returntype="string" access="public">
<cfscript>
var loc = {};
loc.args = "name,table,referenceTable,column,referenceColumn,onUpdate,onDelete";
loc.iEnd = ListLen(loc.args);
loc.adapterArgs = {};
for (loc.i = 1; loc.i <= loc.iEnd; loc.i++) {
loc.argumentName = ListGetAt(loc.args, loc.i);
loc.adapterArgs[loc.argumentName] = this[loc.argumentName];
}
return this.adapter.foreignKeySQL(argumentcollection: loc.adapterArgs);
</cfscript>
</cffunction>
</cfcomponent>