Code Monkey home page Code Monkey logo

defaultscope's Introduction

= DefaultScope

* http://cfwheels.org/plugins/listing/23
* http://github.com/illuminerdi/DefaultScope
* http://cfwheels.org
* http://illuminerdi.com

== DESCRIPTION:

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.

== FEATURES/PROBLEMS:

Features:
* Adds the functionality of ActiveRecord::Base#default_scope to Wheels
* defaultScope() takes all of the same options as findAll() and stores them for a specific model
* findAll() now pulls in defaultScope values and uses them if not manually overridden

Problems:
* If for some reason you decide to use ordered arguments rather than named arguments, then it won't work. The new findAll() expects named arguments only.
* The plugin could do with some testing and better documentation. Also, it would probably be good to steer away from my ... unorthodox method of defining arguments for methods.
* There's no consideration for environment at this time. It might be a good idea to cache the values from defaultScope() if you're in production mode. I need to learn how to do that.
* findAll() is used by the calculations methods (count, sum, average, etc.), which due to the SQL methods they use can't take an 'order' parameter. These methods are not making sure this parameter isn't being passed to findAll(), so this plugin now strips out the 'order' parameter before the calculations methods run. (Thanks, andybellenie, and you can see his path request for CFWheels to fix this at http://code.google.com/p/cfwheels/issues/detail?id=366)

== SYNOPSIS:

<!--- 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="last_name, first_name") />
</cffunction>

== REQUIREMENTS:

* ColdFusion 8+
* CFWheels 1.0+

== INSTALL:

* download DefaultScope-0.6.3.zip from the plugin listing above and place it in /plugins and then Reload the framework

== LICENSE:

(The MIT License)

Copyright (c) 2010 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.

defaultscope's People

Contributors

andybellenie avatar illuminerdi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

defaultscope's Issues

Issues with Wheels 1.1

Hey Josh - it looks like there's some issues with in the DefaultScope plugin and the Wheels 1.1 release. Hopefully you can take a look at it when you have time. Thanks! -Brian

The element at position 1 cannot be found.

The error occurred in D:\site\wwwroot\wheels\model\sql.cfm: line 445
Called from D:\site\wwwroot\wheels\model\sql.cfm: line 353
Called from D:\site\wwwroot\wheels\model\crud.cfm: line 222
Called from D:\site\wwwroot\plugins\defaultscope\DefaultScope.cfc: line 35
Called from D:\site\wwwroot\controllers\Pages.cfc: line 8
Called from D:\site\wwwroot\wheels\global\cfml.cfm: line 174
Called from D:\site\wwwroot\wheels\controller\processing.cfm: line 85
Called from D:\site\wwwroot\wheels\controller\processing.cfm: line 60
Called from D:\site\wwwroot\wheels\dispatch\request.cfm: line 285
Called from D:\site\wwwroot\wheels\index.cfm: line 1
Called from D:\site\wwwroot\rewrite.cfm: line 1
Called from D:\site\wwwroot\wheels\events\onrequest.cfm: line 1
443 : if (loc.i < ListLen(loc.where, "?"))
444 : {
445 : loc.column = loc.params[loc.i].column;
446 : ArrayAppend(loc.returnValue, "#loc.column# #loc.params[loc.i].operator#");
447 : loc.param = {type=loc.params[loc.i].type, dataType=loc.params[loc.i].dataType, scale=loc.params[loc.i].scale, list=loc.params[loc.i].list};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.