Skip to content

Commit c8cb723

Browse files
committed
Guides Update
Updated the guides and removed the use of application.wo prefix. Updated the tests.yml file and enabled the adobe 2018 with sql server test suite.
1 parent e3a51f8 commit c8cb723

29 files changed

+168
-175
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ jobs:
4141
# dbengine: mysql
4242
# - cfengine: adobe@2018
4343
# dbengine: postgres
44-
- cfengine: adobe@2018
45-
dbengine: sqlserver_cicd
44+
# - cfengine: adobe@2018
45+
# dbengine: sqlserver_cicd
4646
- cfengine: adobe@2018
4747
dbengine: h2
4848
# - cfengine: adobe@2021

guides/database-interaction-through-models/associations.md

Lines changed: 32 additions & 32 deletions
Large diffs are not rendered by default.

guides/database-interaction-through-models/calculated-properties.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ For example, let's say that we only want to use `age` to return users who are in
7676
Example Code
7777

7878
```javascript
79-
users = application.wo.model("user").findAll(
79+
users = model("user").findAll(
8080
where="age >= 20 AND age < 30", order="age DESC"
8181
);
8282
```
@@ -87,7 +87,7 @@ By default, calculated properties will return `char` as the column data type. Wh
8787

8888
```javascript
8989
property(
90-
name="createdAtAlias",
90+
name="createdAtAlias",
9191
sql="posts.createdat",
9292
dataType="datetime"
9393
);

guides/database-interaction-through-models/column-statistics.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Let's start with the [count()](https://api.cfwheels.org/model.count.html) functi
1717
To count how many rows you have in your `authors` table, simply do this:
1818

1919
```javascript
20-
authorCount = application.wo.model("author").count();
20+
authorCount = model("author").count();
2121
```
2222

2323
What if you only want to count authors with a last name starting with "A"? Like the [findAll()](https://api.cfwheels.org/model.findall.html) function, [count()](https://api.cfwheels.org/model.count.html) will accept a `where` argument, so you can do this:
2424

2525
```javascript
26-
authorCount = application.wo.model("author").count(where="lastName LIKE 'A%'");
26+
authorCount = model("author").count(where="lastName LIKE 'A%'");
2727
```
2828

2929
Simple enough. But what if you wanted to count only authors in the USA, and that information is stored in a different table? Let's say you have stored country information in a table called `profiles` and also setup a `hasOne` / `belongsTo` association between the `author` and `profile` models.
@@ -33,13 +33,13 @@ Just like in the [findAll()](https://api.cfwheels.org/model.findall.html) functi
3333
In our case, the code would end up looking something like this:
3434

3535
```javascript
36-
authorCount = application.wo.model("author").count(include="profile", where="countryId=1 AND lastName LIKE 'A%'");
36+
authorCount = model("author").count(include="profile", where="countryId=1 AND lastName LIKE 'A%'");
3737
```
3838

3939
Or, if you care more about readability than performance, why not just join in the `countries` table as well?
4040

4141
```javascript
42-
authorCount = application.wo.model("author").count(include="profile(country)", where="name='USA' AND lastName LIKE 'A%'");
42+
authorCount = model("author").count(include="profile(country)", where="name='USA' AND lastName LIKE 'A%'");
4343
```
4444

4545
In the background, these functions all perform SQL that looks like this:
@@ -57,7 +57,7 @@ However, if you include a `hasMany` association, CFWheels will be smart enough t
5757
For example, the following method call:
5858

5959
```javascript
60-
authorCount = application.wo.model("author").count(include="books", where="title LIKE 'Wheels%'");
60+
authorCount = model("author").count(include="books", where="title LIKE 'Wheels%'");
6161
```
6262

6363
Will execute this SQL (presuming `id` is the primary key of the `authors` table and the correct associations have been setup):
@@ -81,7 +81,7 @@ The same goes for the remaining column statistics functions as well; they all ac
8181
Here's an example of getting the average salary in a specific department:
8282

8383
```javascript
84-
avgSalary = application.wo.model("employee").average(property="salary", where="departmentId=1");
84+
avgSalary = model("employee").average(property="salary", where="departmentId=1");
8585
```
8686

8787
You can also pass in `distinct=true` to this function if you want to include only each unique instance of a value in the average calculation.
@@ -93,8 +93,8 @@ To get the highest and lowest values for a property, you can use the [minimum()]
9393
They are pretty self explanatory, as you can tell by the following examples:
9494

9595
```javascript
96-
highestSalary = application.wo.model("employee").maximum("salary");
97-
lowestSalary = application.wo.model("employee").minimum("salary");
96+
highestSalary = model("employee").maximum("salary");
97+
lowestSalary = model("employee").minimum("salary");
9898
```
9999

100100
### Getting the Sum of All Values
@@ -106,15 +106,15 @@ As you have probably already figured out, [sum()](https://api.cfwheels.org/model
106106
Let's wrap up this chapter on a happy note by getting the total dollar amount you've made:
107107

108108
```javascript
109-
howRichAmI = application.wo.model("invoice").sum("billedAmount");
109+
howRichAmI = model("invoice").sum("billedAmount");
110110
```
111111

112112
### Grouping Your Results
113113

114114
All of the methods we've covered in this chapter accepts the `group` argument. Let's build on the example with getting the average salary for a department above, but this time, let's get the average for all departments instead.
115115

116116
```javascript
117-
avgSalaries = application.wo.model("employee").average(property="salary", group="departmentId");
117+
avgSalaries = model("employee").average(property="salary", group="departmentId");
118118
```
119119

120120
When you choose to group results like this you get a `cfquery` result set back, as opposed to a single value.

guides/database-interaction-through-models/creating-records.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ description: How to create new objects and save them to the database.
77
In Wheels, one way to create objects that represent records in our table is by calling the [new()](https://api.cfwheels.org/model.new.html) class-level method.
88

99
```javascript
10-
newAuthor = application.wo.model("author").new();
10+
newAuthor = model("author").new();
1111
```
1212

1313
We now have an empty `Author` object that we can start filling in properties for. These properties correspond with the columns in the `authors` database table, unless you have mapped them specifically to columns with other names (or mapped to an entirely different table).
@@ -30,7 +30,7 @@ If you want to create a new object based on parameters sent in from a form reque
3030
Given that `params.newAuthor` is a struct containing the `firstName` and `lastName` variables, the code below does the same as the code above (without saving it though).
3131

3232
```javascript
33-
newAuthor = application.wo.model("author").new(params.newAuthor);
33+
newAuthor = model("author").new(params.newAuthor);
3434
```
3535

3636
### Saving Straight to the Database
@@ -39,7 +39,7 @@ If you want to save a new author to the database right away, you can use the [cr
3939

4040
{% code title="" %}
4141
```javascript
42-
application.wo.model("author").create(params.newAuthor);
42+
model("author").create(params.newAuthor);
4343
```
4444
{% endcode %}
4545

@@ -51,7 +51,7 @@ This means you can read the value by doing something like this. (This example as
5151

5252
```javascript
5353
<cfscript>
54-
newAuthor = application.wo.model("author").new();
54+
newAuthor = model("author").new();
5555
newAuthor.firstName = "Joe";
5656
newAuthor.lastName = "Jones";
5757
newAuthor.save();
@@ -72,7 +72,7 @@ However, unlike the primary key, Wheels will not automatically load database def
7272
Of course, if you do need to access the database default immediately after saving, Wheels allows this. Simply add `reload=true` to the [create()](https://api.cfwheels.org/model.create.html), [update()](https://api.cfwheels.org/model.update.html), or [save()](https://api.cfwheels.org/model.save.html) methods:
7373

7474
```javascript
75-
newAuthor = application.wo.model("author").new();
75+
newAuthor = model("author").new();
7676
newAuthor.firstName = "Joe";
7777
newAuthor.lastName = "Jones";
7878
newAuthor.save(reload=true);
@@ -89,7 +89,7 @@ property(name="welcomeText", defaultValue="Hello world!");
8989
This is effectively the same as doing this:
9090

9191
```javascript
92-
application.wo.model("myModel").new(welcomeText="Hello world!");
92+
model("myModel").new(welcomeText="Hello world!");
9393
```
9494

9595
..except you only need to set it once per model.

guides/database-interaction-through-models/deleting-records.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ If you're unfamiliar with the concept of callbacks, you can read about them in t
2323
Here's a simple example of fetching a record from the database and then deleting it.
2424

2525
```javascript
26-
aPost = application.wo.model("post").findByKey(33);
26+
aPost = model("post").findByKey(33);
2727
aPost.delete();
2828
```
2929

guides/database-interaction-through-models/dirty-records.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Let's look at the methods Wheels provide to make tracking these changes easier f
2525
Let's get to coding…
2626

2727
```javascript
28-
post = application.wo.model("post").findByKey(1);
28+
post = model("post").findByKey(1);
2929
result = post.hasChanged();
3030
```
3131

guides/database-interaction-through-models/dynamic-finders.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ The concept is simple. Instead of using arguments to tell CFWheels what you want
1111
For example, the following code:
1212

1313
```javascript
14-
me = application.wo.model("user").findOne(where="email='me@myself.com'");
14+
me = model("user").findOne(where="email='me@myself.com'");
1515
```
1616

1717
Can also be written as:
1818

1919
```javascript
20-
me = application.wo.model("user").findOneByEmail("me@myself.com");
20+
me = model("user").findOneByEmail("me@myself.com");
2121
```
2222

2323
Through the power of `onMissingMethod()`, CFWheels will parse the method name and figure out that the value supplied is supposed to be matched against the `email` column.
@@ -27,7 +27,7 @@ Through the power of `onMissingMethod()`, CFWheels will parse the method name an
2727
You can take this one step further by using code such as:
2828

2929
```javascript
30-
me = application.wo.model("user").findOneByUserNameAndPassword("bob,pass");
30+
me = model("user").findOneByUserNameAndPassword("bob,pass");
3131
```
3232

3333
In this case, CFWheels will split the function name on the And part and determine that you want to find the record where the username column is "bob" and the password column is "pass".
@@ -45,13 +45,13 @@ In the background, these dynamically-named methods just pass along execution to
4545
The below code, for example, is perfectly valid:
4646

4747
```javascript
48-
users = application.wo.model("user").findAllByState(value="NY", order="name", page=3);
48+
users = model("user").findAllByState(value="NY", order="name", page=3);
4949
```
5050

5151
When passing in multiple arguments like above, you have to start naming them instead of relying on the order of the arguments though. When doing so, you need to name the argument `value` if you're passing in just one value and `values` if you're passing in multiple values in a list. In other words, you need to name it `values` when calling an `And`type dynamic finder.
5252

5353
```javascript
54-
users = application.wo.model("user").findAllByCityAndState(
54+
users = model("user").findAllByCityAndState(
5555
values="Buffalo,NY", order="name", page=3
5656
);
5757
```

guides/database-interaction-through-models/getting-paginated-data.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This chapter will deal with the first part: getting the paginated data. Please p
2222
Let's jump straight to an example:
2323

2424
```javascript
25-
authors = application.wo.model("Author").findAll(page=2, perPage=25, order="lastName");
25+
authors = model("Author").findAll(page=2, perPage=25, order="lastName");
2626
```
2727

2828
That simple code will return authors 26-50 from the database, ordered by their last name.
@@ -32,7 +32,7 @@ What SQL statements are actually being executed depends on which database engine
3232
One important thing that you should be aware of is that pagination is done based on objects and not records. To illustrate what that means, we can expand on the above example a little:
3333

3434
```javascript
35-
authorsAndBooks = application.wo.model("Author").findAll(
35+
authorsAndBooks = model("Author").findAll(
3636
include="Books", page=2, perPage=25, order="lastName"
3737
);
3838
```
@@ -42,7 +42,7 @@ Here, we tell Wheels that we also want to include any books written by the autho
4242
If you do want to paginate based on the books instead, all that you need to do is flip the `findAll()` statement around a little:
4343

4444
```javascript
45-
booksAndAuthors = application.wo.model("Book").findAll(
45+
booksAndAuthors = model("Book").findAll(
4646
include="Author", page=2, perPage=25, order="lastName"
4747
);
4848
```

guides/database-interaction-through-models/nested-properties.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ First, in our controller, let's set the data needed for our form:
3333

3434
{% code title="app/controllers/User.cfc" %}
3535
```javascript
36-
// In app/controllers/User.cfc
36+
// In app/controllers/User.cfc
3737
function new() {
38-
var newProfile = application.wo.model("profile").new();
39-
user = application.wo.model("user").new(profile=newProfile);
38+
var newProfile = model("profile").new();
39+
user = model("user").new(profile=newProfile);
4040
}
4141
```
4242
{% endcode %}
@@ -50,7 +50,7 @@ If this were an `edit` action calling an existing object, our call would need to
5050
{% code title="app/controllers/User.cfc" %}
5151
```javascript
5252
function edit() {
53-
user = application.wo.model("user").findByKey(key=params.key, include="profile");
53+
user = model("user").findByKey(key=params.key, include="profile");
5454
}
5555
```
5656
{% endcode %}
@@ -100,7 +100,7 @@ You may be surprised to find out that our standard `create` action does not chan
100100
{% code title="app/controllers/Users.cfc" %}
101101
```javascript
102102
function create() {
103-
user = application.wo.model("user").new(params.user);
103+
user = model("user").new(params.user);
104104
if ( user.save() ) {
105105
flashInsert(success="The user was created successfully.");
106106
redirectTo(controller=params.controller);
@@ -123,7 +123,7 @@ For the `edit` scenario, this is what our `update` action would look like (which
123123
{% code title="app/controllers/Users.cfc" %}
124124
```javascript
125125
function update() {
126-
user = application.wo.model("user").findByKey(params.user.id);
126+
user = model("user").findByKey(params.user.id);
127127
if ( user.update(params.user) ) {
128128
flashInsert(success="The user was updated successfully.");
129129
redirectTo(action="edit");
@@ -186,8 +186,8 @@ In this example, we'll just put one new `address` in the array.
186186
{% code title="app/controllers/Users.cfc" %}
187187
```javascript
188188
function new() {
189-
var newAddresses = [ application.wo.model("address").new() ];
190-
user = application.wo.model("user").new(addresses=newAddresses);
189+
var newAddresses = [ model("address").new() ];
190+
user = model("user").new(addresses=newAddresses);
191191
}
192192
```
193193
{% endcode %}
@@ -197,7 +197,7 @@ In the `edit` scenario, we just need to remember to call the `include` argument
197197
{% code title="app/controllers/Users.cfc" %}
198198
```javascript
199199
function edit() {
200-
user = application.wo.model("user").findByKey(key=params.key, include="addresses");
200+
user = model("user").findByKey(key=params.key, include="addresses");
201201
}
202202
```
203203
{% endcode %}
@@ -307,15 +307,15 @@ component extends="Model" {
307307
}
308308

309309
}
310-
// app/models/Publication.cfc
310+
// app/models/Publication.cfc
311311
component extends="Model" {
312312

313313
public function config() {
314314
hasMany("subscriptions");
315315
}
316316

317317
}
318-
// app/models/Subscription.cfc
318+
// app/models/Subscription.cfc
319319
component extends="Model" {
320320

321321
public function config() {
@@ -337,9 +337,9 @@ Here is how we would set up the nested properties in the `customer` model for th
337337
component extends="Model" {
338338

339339
public function config() {
340-
// Associations
340+
// Associations
341341
hasMany(name="subscriptions", shortcut="publications");
342-
// Nested properties
342+
// Nested properties
343343
nestedProperties(
344344
associations="subscriptions",
345345
allowDelete=true
@@ -357,11 +357,11 @@ Let's define the data needed in an `edit` action in the controller at `app/contr
357357
{% code title="app/controllers/Customers.cfc" %}
358358
```javascript
359359
function edit() {
360-
customer = application.wo.model("customer").findByKey(
360+
customer = model("customer").findByKey(
361361
key=params.key,
362362
include="subscriptions"
363363
);
364-
publications = application.wo.model("publication").findAll(order="title");
364+
publications = model("publication").findAll(order="title");
365365
}
366366
```
367367
{% endcode %}
@@ -437,8 +437,8 @@ You'll notice that this example `update` action is fairly standard for a Wheels
437437
{% code title="app/controllers/Customers.cfc" %}
438438
```javascript
439439
function update() {
440-
// Load customer object
441-
customer = application.wo.model("customer").findByKey(params.customer.id);
440+
// Load customer object
441+
customer = model("customer").findByKey(params.customer.id);
442442
/* If update is successful, generate success message
443443
and redirect back to edit screen */
444444
if ( customer.update(params.customer) ) {

0 commit comments

Comments
 (0)