Skip to content

Commit

Permalink
🐛 Make Criteria#contains(value) work as expected on array fields
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Feb 5, 2024
1 parent c404ea0 commit ce9c7d7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Refactor loading of requirements
* The `Alchemy.ClientSession` class should now be used as a map to store session data
* Fix `Field.Schema` contents not being converted from database representation when the schema also has a relation
* Make `Criteria#contains(value)` work as expected on array fields

## 1.3.22 (2023-12-21)

Expand Down
20 changes: 15 additions & 5 deletions lib/app/helper_datasource/00-nosql_datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
* @since 1.1.0
* @version 1.1.0
*/
var NoSQL = Function.inherits('Alchemy.Datasource', function Nosql(name, options) {
Nosql.super.call(this, name, options);
});
var NoSQL = Function.inherits('Alchemy.Datasource', 'Nosql');

/**
* All comparison functions
Expand Down Expand Up @@ -590,7 +588,7 @@ NoSQL.setStatic(function areComparable(a, b) {
*
* @author Jelle De Loecker <[email protected]>
* @since 1.1.0
* @version 1.3.16
* @version 1.4.0
*
* @param {Criteria} criteria
* @param {Group} group
Expand Down Expand Up @@ -765,7 +763,19 @@ NoSQL.setMethod(function compileCriteria(criteria, group) {
} else if (item.type == 'equals') {
obj = item.value;
} else if (item.type == 'contains') {
obj = RegExp.interpret(item.value);

let do_regexp_search = true;

if (entry.field) {
if (entry.field.is_array || entry.field.options?.type == 'HasAndBelongsToMany') {
do_regexp_search = false;
obj = item.value;
}
}

if (do_regexp_search) {
obj = RegExp.interpret(item.value);
}
} else if (item.type == 'in') {

// @TODO: This shouldn't be needed,
Expand Down

0 comments on commit ce9c7d7

Please sign in to comment.