FORGEBOX Enterprise 🚀 - Take your ColdFusion (CFML) Development to Modern Times! Learn More...

CFWheels Models Default Scope

v0.0.12 Public

Plugin: Default Scope

Description

The main purpose of the Default Scope plugin is to provide a solution to set the default scope for your findAll() method. For example, a model can be configured to predefine the fields to select when calling the findAll() method.

You can specify the default values for the following attributes:

  • where
  • order
  • group
  • select
  • distinct
  • include
  • maxRows
  • page
  • perPage
  • count
  • handle
  • cache
  • reload
  • parameterize
  • returnAs
  • returnIncluded
  • callbacks
  • includeSoftDeletes

This Plugin is an adaptation of the original CFWheels DefaultScope plugin created by Joshua Clingenpeel - https://github.com/illuminerdi/DefaultScope

Requirements

Coldfusion

  • Lucee 5
  • Adobe Coldfusion 2016

Usage

Model Setup

Basic model setup

component extends="Model" {
    function config(){
        table("tableName");
        defaultScope(
            select="title, description, author, publisheddate"
        );
    }
}

Appending defaultScope attributes

component extends="Model" {
	function config(){
        table("tableName");
        defaultScope(
            select="title, description, author, publisheddate"
        );
        defaultScope(
            select="category"
        );
    }
}

Controller Usage

component extends="app.models.model" {
	function config(){
        table("orders");
        defaultScope(
            order="orderDate,requiredDate",
            select="orderNumber, status, comments",
            maxRows=10
        );
        defaultScope(
            select="customerNumber"
        );
    }
}

// will in turn call model("order").findAll()
model("order").findAll(exclusive=true);

// will in turn call model("order").findAll(order="orderDate,requiredDate", select="orderNumber,status,comments,customerNumber", maxRows=10);
model("order").findAll();

// will in turn call model("order").findAll(order="orderDate,requiredDate", select="orderNumber,status,comments,customerNumber", maxRows=5);
model("order").findAll(maxRows=5);
model("order").findAll(maxRows=5, inclusive=false);

// will in turn call model("order").findAll(order="orderDate,requiredDate", select="orderNumber,status,comments,customerNumber", maxRows=10);
model("order").findAll(maxRows=5, inclusive=true);

// will in turn call model("order").findAll(order="orderDate,requiredDate", select="amount,orderNumber,status,comments,customerNumber", maxRows=10);
model("order").findAll(select="amount", inclusive=true);

Parameters - findAll()

ParameterTypeRequiredDefaultDescription
exclusivebooleanfalsefalsetoggles defaultScope on or off - when true, default functionality found in CFWheels findAll() will work as expected
inclusivebooleanfalsefalsewhen set to true, inclusive will append the values found in the findAll() with the values defined in the default scope. When set to false, the values defined in the findAll() will replace the values defined in the default scope.

Here are all the versions for this package. Please note that you can leverage CommandBox package versioning to install any package you like. Please refer to our managing package version guide for more information.

Version Created Last Update Published By Stable Actions
Current
0.0.12 Aug 09 2019 11:05 AM Aug 09 2019 11:05 AM
Version History
0.0.11 Aug 09 2019 10:59 AM Aug 09 2019 10:59 AM
0.0.10 Aug 09 2019 10:47 AM Aug 09 2019 10:47 AM
0.0.9 Aug 09 2019 10:36 AM Aug 09 2019 10:36 AM
0.0.8 Aug 08 2019 04:55 PM Aug 08 2019 04:55 PM
0.0.7 Aug 08 2019 04:48 PM Aug 08 2019 04:48 PM
0.0.6 Aug 08 2019 03:49 PM Aug 08 2019 03:49 PM
0.0.5 Aug 08 2019 03:35 PM Aug 08 2019 03:35 PM
0.0.4 Aug 08 2019 03:34 PM Aug 08 2019 03:34 PM
0.0.3 Aug 08 2019 03:11 PM Aug 08 2019 03:11 PM
0.0.2 Aug 08 2019 03:10 PM Aug 08 2019 03:10 PM

 

No collaborators yet.
   
  • Aug 08 2019 03:10 PM
  • Aug 09 2019 11:05 AM
  • 38
  • 0
  • 11