mirror of
https://github.com/processwire/processwire.git
synced 2025-08-21 14:02:59 +02:00
Add pages.find selector support for matching repeaters with no row present in field_repeater table. Examples: repeater_field.count=0, repeater_field.count<2, repeater_field.count!=1, repeater_field.count>=0, etc. Previously these would only match if the page having the repeater field had been saved at least once since the repeater field was added (and thus it had a DB row to match). Now it no longer needs a DB row present to match 0 count. Related to processwire/processwire-issues#1701
This commit is contained in:
@@ -1528,12 +1528,12 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule {
|
|||||||
/**
|
/**
|
||||||
* Update a DatabaseQuerySelect object to match a Page
|
* Update a DatabaseQuerySelect object to match a Page
|
||||||
*
|
*
|
||||||
* @param DatabaseQuerySelect $query
|
* @param PageFinderDatabaseQuerySelect $query
|
||||||
* @param string $table
|
* @param string $table
|
||||||
* @param string $subfield
|
* @param string $subfield
|
||||||
* @param string $operator
|
* @param string $operator
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @return DatabaseQuerySelect
|
* @return PageFinderDatabaseQuerySelect
|
||||||
* @throws WireException
|
* @throws WireException
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -1546,22 +1546,13 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule {
|
|||||||
|
|
||||||
if( ($operator == '=' && $value == 0) ||
|
if( ($operator == '=' && $value == 0) ||
|
||||||
(in_array($operator, array('<', '<=')) && $value > -1) ||
|
(in_array($operator, array('<', '<=')) && $value > -1) ||
|
||||||
($operator == '!=' && $value)) {
|
($operator == '!=' && $value) || ($operator === '>=' && $value == 0)) {
|
||||||
|
|
||||||
$templateIDs = array();
|
$fieldTable = $field->getTable();
|
||||||
foreach($field->getTemplates() as $template) {
|
$joinTable = "cnt_repeater_$table";
|
||||||
/** @var Template $template */
|
$parentQuery = $query->parentQuery;
|
||||||
$templateIDs[] = (int) $template->id;
|
$parentQuery->leftjoin("$fieldTable AS $joinTable ON $joinTable.pages_id=pages.id");
|
||||||
}
|
$parentQuery->where("($joinTable.count{$operator}$value OR $joinTable.pages_id IS NULL)");
|
||||||
if(count($templateIDs)) {
|
|
||||||
$templateIDs = implode(',', $templateIDs);
|
|
||||||
$sql =
|
|
||||||
"($table.count{$operator}$value OR " .
|
|
||||||
"($table.count IS NULL AND pages.templates_id IN($templateIDs)))";
|
|
||||||
$query->where($sql);
|
|
||||||
} else {
|
|
||||||
$query->where("1>2"); // forced non-match
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$query->where("($table.count{$operator}$value)");
|
$query->where("($table.count{$operator}$value)");
|
||||||
|
Reference in New Issue
Block a user