Cms: Element `$query->getCrtiteria()` bug

Created on 4 Dec 2020  路  2Comments  路  Source: craftcms/cms

Description

It doesn't look like the getCriteria() method picks up relatedTo criteria set by the field name eg.

$query->customFieldHandle(100);
vs
$query->relatedTo([ 'targetElement' => 100, 'field' =>'customFieldHandle' ]);

Steps to reproduce

// $criteria array does NOT contain any relatedTo criteria
$query = Entry::find();
$query->customFieldHandle(100);
$criteria = $query->getCriteria();
// $criteria array does contain the relatedTo criteria
$query = Entry::find();
$query->relatedTo([ 'targetElement' => 100, 'field' =>'customFieldHandle' ]);
$criteria = $query->getCriteria(); 

Additional info

  • Craft version: 3.5.16
  • PHP version: 7.3
bug

All 2 comments

Good catch! Just fixed this for the next release.

Craft 3.5.17 is out now with this fix.

Was this page helpful?
0 / 5 - 0 ratings