db icon indicating copy to clipboard operation
db copied to clipboard

Setting escapingReplacements property of the LikeCondition

Open easyrider7522 opened this issue 6 years ago • 2 comments

Object Form in yii\db\Query conditions introduced in Yii 2.0.14 is really great and timely enhancement!

It would be nice although setting its escapingReplacements property in a more convenient way, than calling its setter method:

    $likeObject->setEscapingReplacements( false );

The property itself is not public but protected, so direct assignment raises exception:

    $likeObject->escapingReplacements = false;

In general, it would be nice to set escapingReplacements at object creation as fouth parameter passed to __construct method, e.g. like this:

    $data = ( new Query())
        ->select([ 'id', 'name' ])
        ->from( 'locality' )
        ->where( new LikeCondition( 'postal', 'LIKE', '12345_', false ))
        ->all();

This would eliminate the need in additional object holding var and code lines:

    $likeObject = new LikeCondition( 'postal', 'LIKE', '12345_' );
    $likeObject->setEscapingReplacements( false );
    $data = ( new Query())
        ->select([ 'id', 'name' ])
        ->from( 'locality' )
        ->where( $likeObject )
        ->all();

Additional info

Q A
Yii version 2.0.14
PHP version 5.6.12
Operating system Windows

easyrider7522 avatar Feb 24 '18 15:02 easyrider7522