Skip to content

Commit

Permalink
Merge pull request #1327 from chapmandu/issue-1319-model-datasource-bug
Browse files Browse the repository at this point in the history
issue #1319 model datasource bug
  • Loading branch information
bpamiri committed Nov 10, 2023
2 parents 8f649ea + 7b2898b commit 0d199a8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion box.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name":"CFWheels",
"version":"2.5.0",
"version":"2.5.1",
"author":"CFWheels Core Team and Community",
"shortDescription":"CFWheels MVC Framework Core Directory",
"location":"ForgeboxStorage",
Expand Down
6 changes: 3 additions & 3 deletions wheels/model/read.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public any function findAll(
boolean callbacks = "true",
boolean includeSoftDeletes = "false",
struct useIndex = {},
string dataSource = application.wheels.dataSourceName,
string dataSource = variables.wheels.class.dataSource,
numeric $limit = "0",
numeric $offset = "0"
) {
Expand Down Expand Up @@ -396,7 +396,7 @@ public any function findByKey(
string returnAs,
boolean callbacks = "true",
boolean includeSoftDeletes = "false",
string dataSource = application.wheels.dataSourceName
string dataSource = variables.wheels.class.dataSource
) {
$args(name = "findByKey", args = arguments);
$setDebugName(name = "FindByKey", args = arguments);
Expand Down Expand Up @@ -445,7 +445,7 @@ public any function findOne(
string returnAs,
boolean includeSoftDeletes = "false",
struct useIndex = {},
string dataSource = application.wheels.dataSourceName
string dataSource = variables.wheels.class.dataSource
) {
$args(name = "findOne", args = arguments);
$setDebugName(name = "findOne", args = arguments);
Expand Down
8 changes: 8 additions & 0 deletions wheels/tests/_assets/models/AuthorAlternateDatasource.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
component extends="Model" {

function config() {
table("authors");
dataSource("wheelstestdb_h2");
}

}
11 changes: 11 additions & 0 deletions wheels/tests/model/read/datasource.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ component extends="wheels.tests.Test" {
finderArgs = {where = "firstName = '#firstName#'", datasource = altDatasource};
}

function test_findall_respects_model_config_datasource() {
if (!isTestable) return;
transaction {
this.db_setup();
// ensure this is using the wheelstestdb_h2 as defined in the model config
actual = model("AuthorAlternateDatasource").findAll(where = "firstName = '#firstName#'");
TransactionRollback();
}
assert("actual.recordCount");
}

function test_findall_with_datasource_argument() {
if (!isTestable) return;
transaction {
Expand Down

0 comments on commit 0d199a8

Please sign in to comment.