PluginsWhat you've got loaded..
Single Table Inheritance 1.1
A plugin for Coldfusion on Wheels by Andy Bellenie
This plugin allows you to store different model classes in a single database table by using a 'type' column to identify to class. For example, you may have many different types of user, but you want to store them all in one table and share some common functionality.
Usage
1. Add the column to distinguish between different classes to your database table. Depending on your application, this could be a number of different datatypes:
- bit: ideal when there are only two subclasses (e.g. pages and sections within a CMS, the column could then be called 'isSection' or 'isPage')
- varchar: good for readability (used in the example below)
- integer: better performance for many class types on very high load applications
2. Create a standard Wheels base class. For this example, it would be called User.cfc
<!--- User.cfc ---> <cfcomponent extends="Model"> </cfcomponent>
3. Create one or more sub-classes that extend the base class, and add a call to the plugin setup function. Remember to add super.init() to your subclass if the parent class also has an init() block.
<!--- Administrator.cfc ---> <cfcomponent extends="User"> <cffunction name="init"> <cfset singleTableInheritance(tableName="users")> </cffunction> </cfcomponent>
<!--- Editor.cfc ---> <cfcomponent extends="User"> <cffunction name="init"> <cfset singleTableInheritance(tableName="users")> </cffunction> </cfcomponent>
singleTableInheritance() accepts the following arguments:
- tableName (string, required) - the name of the table
- typeColumn (string, defaults to 'type') - the name of the column used to differentiate between different types of models (can be any simple value, a string, integer, bit etc...)
- typeValue (string, defauls to the model name of the sub-class, in this case 'Administrator' or 'Editor')
- model("Administrator").findAll() - returns all administrators
- model("User").findAll() - returns all editors and administrators
- model("Editor").deleteAll() - deletes all editors, etc.
Support
I try to keep my plugins free from bugs and up to date with Wheels releases, but if you encounter a problem please log an issue using the tracker on github, where you can also browse my other plugins.
https://github.com/andybellenie