-
Notifications
You must be signed in to change notification settings - Fork 19
oracle
Troy Murray edited this page Sep 19, 2011
·
1 revision
When using Oracle, when you create a new table a corresponding sequence is created [tablename_seq] for use for primary key values.
To make use of this however you'll need to change your model to implement a beforeCreate() callback that sets the id value based on the next value in the sequence.
<cfcomponent extends="Model" output="false">
<cffunction name="init">
<cfset beforeCreate("getPrimaryKeyValue")>
</cffunction>
<cffunction name="getPrimkaryKeyValue)">
<cfquery datasource="#get('dataSourceName')#" name="nextSequenceValue">
SELECT
[tablename_seq].NEXTVAL AS ID
FROM
dual;
</cfquery>
<cfset this.id = nextSequenceValue.ID/>
</cffunction>
</cfcomponent>