mirror of
https://github.com/processwire/processwire.git
synced 2025-08-20 13:31:48 +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
|
||||
*
|
||||
* @param DatabaseQuerySelect $query
|
||||
* @param PageFinderDatabaseQuerySelect $query
|
||||
* @param string $table
|
||||
* @param string $subfield
|
||||
* @param string $operator
|
||||
* @param string $value
|
||||
* @return DatabaseQuerySelect
|
||||
* @return PageFinderDatabaseQuerySelect
|
||||
* @throws WireException
|
||||
*
|
||||
*/
|
||||
@@ -1546,22 +1546,13 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule {
|
||||
|
||||
if( ($operator == '=' && $value == 0) ||
|
||||
(in_array($operator, array('<', '<=')) && $value > -1) ||
|
||||
($operator == '!=' && $value)) {
|
||||
($operator == '!=' && $value) || ($operator === '>=' && $value == 0)) {
|
||||
|
||||
$templateIDs = array();
|
||||
foreach($field->getTemplates() as $template) {
|
||||
/** @var Template $template */
|
||||
$templateIDs[] = (int) $template->id;
|
||||
}
|
||||
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
|
||||
}
|
||||
$fieldTable = $field->getTable();
|
||||
$joinTable = "cnt_repeater_$table";
|
||||
$parentQuery = $query->parentQuery;
|
||||
$parentQuery->leftjoin("$fieldTable AS $joinTable ON $joinTable.pages_id=pages.id");
|
||||
$parentQuery->where("($joinTable.count{$operator}$value OR $joinTable.pages_id IS NULL)");
|
||||
|
||||
} else {
|
||||
$query->where("($table.count{$operator}$value)");
|
||||
|
Reference in New Issue
Block a user