DefaultScope

The DefaultScope plugin seeks to add the functionality of Rails' ActiveRecord::Base#default_scope to Wheels. While you can use set() right now in Wheels to alter the global defaults of the findAll() method, you can't set a scope for individual models. With this plugin, you can specify default values for the findAll() method on a specific model.

This plugin overrides the findAll() method and adds a new method called defaultScope().

New Methods

This method is mixed in to your Models and is meant to be invoked from the init() method. It takes all of the same optional arguments as the findAll() method, and will set them as defaults for future calls to that method.

<!--- in any model --->
<cffunction name="init">
	<!--- assume we have a model containing user information, and
		you want to sort by the last name then first for most of your
		findAll() requests.  --->
	<cfset defaultScope(order="lastName, firstName") />
</cffunction>

Overridden Methods

While this method has been overridden in order to accommodate the new defaultScope settings, it still behaves the same as it did before. Use it the way you normally would. Just remember that you might have set some values in the defaultScope(). If you set new values for the same parameters here, those values will override the values set in defaultScope().

How to Use

Install it! Then the new method is automatically available to you.

Uninstallation

All you need to do is delete the /plugins/DefaultScope-x.x.zip file.

Thanks

To the rather active CFWheels Google group, and especially James Gibson who helped squirrel out an annoying bug during the initial development.

Release History

Problems/Known Issues

License

(The MIT License)

Copyright (c) 2009 Joshua Clingenpeel

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Warnings: The FallbackImage plugin may be incompatible with this version of Wheels, please look for a compatible version of the plugin
The LogUserAction plugin may be incompatible with this version of Wheels, please look for a compatible version of the plugin
The RequiredFields plugin may be incompatible with this version of Wheels, please look for a compatible version of the plugin
The JsonProperties plugin may be incompatible with this version of Wheels, please look for a compatible version of the plugin
The DefaultScope plugin may be incompatible with this version of Wheels, please look for a compatible version of the plugin
The Attachments plugin may be incompatible with this version of Wheels, please look for a compatible version of the plugin
The localerb plugin may be incompatible with this version of Wheels, please look for a compatible version of the plugin
The AssetBundler plugin may be incompatible with this version of Wheels, please look for a compatible version of the plugin
The PluginPackager plugin may be incompatible with this version of Wheels, please look for a compatible version of the plugin
The inWords plugin may be incompatible with this version of Wheels, please look for a compatible version of the plugin
Application: AlexTasselV3 [Run Tests]
Framework: Wheels 1.1.8
CFML Engine: Adobe ColdFusion 9,0,1,274733
Default Data Source: alextassel
Active Environment: Design
URL Rewriting: On
URL Obfuscation: Off
Plugins: FallbackImage
LogUserAction
RequiredFields
DefaultScope
JsonProperties
simpleProperties
Attachments
AssetBundler
localerb
inWords
PluginPackager
Route: home
Controller: Wheels
Action: wheels
Additional Params: name = defaultscope
view = plugins
Caching Stats: hits: 0, misses: 0, culls: 0
Execution Time: 15ms (view ~15ms, action ~15ms)