$editor->where with string operators

$editor->where with string operators

VitalizVitaliz Posts: 71Questions: 7Answers: 1
edited January 2016 in Editor

Hi,Allan.
I tried use string operation in editor's ->where , but always get error

SQLSTATE[42S22]: Column not found: 1054 Unknown column '3' in 'where clause'", data: []

(then $my_id=3)

$my_id=$_POST['my_id'];
//echo 'cur_id='.$cur_id."<br>\n";
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'modx_vkrzakaz','id' )
    ->fields(
        Field::inst( 'modx_vkrzakaz.no_zak' ) ,
        Field::inst( 'modx_vkrzakaz.kli_zak' )
            ->options( 'modx_vkrklient', 'id', 'fio' ),
        Field::inst( 'modx_vkrklient.fio' ),
        Field::inst( 'modx_vkrzakaz.avt_zak' )
            ->options( 'modx_vkravtor', 'id', 'name' ),
        Field::inst( 'modx_vkravtor.name' ),
        Field::inst( 'modx_vkrzakaz.vid_zak' )
            ->options( 'modx_vkrvidzak', 'id', 'vidname' ),
        Field::inst( 'modx_vkrvidzak.vidname' ),
        Field::inst( 'modx_vkrzakaz.is_step1' ),
        Field::inst( 'modx_vkrzakaz.is_step2' ),
        Field::inst( 'modx_vkrzakaz.is_step3' ),
        Field::inst( 'modx_vkrzakaz.is_step4' ),
        Field::inst( 'modx_vkrzakaz.is_step5' ),
        Field::inst( 'modx_vkrzakaz.is_step6' ),
        Field::inst( 'modx_vkrzakaz.is_step7' ),
        Field::inst( 'modx_vkrzakaz.tema_zak' ),
                Field::inst( 'modx_vkrzakaz.predpr_zak' ),
                Field::inst( 'modx_vkrzakaz.srok_zak' )
                ->validator( 'Validate::dateFormat', array(
                    "empty" => false,
                    "format" => Format::DATE_ISO_8601,
                    "message" => "Введите дату в формате гггг-мм-дд"
            ) )
            ->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
            ->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 ),
                Field::inst( 'modx_vkrzakaz.sum' ),
        Field::inst( 'modx_vkrzakaz.sum_opl' ),
        Field::inst( 'modx_vkrzakaz.priority' ),
                Field::inst( 'modx_vkrzakaz.avt_list' )
    )  
       
       ->where('modx_vkrzakaz.avt_zak',$my_id)
       ->where( 'LOCATE("'+$my_id+'", modx_vkrzakaz.avt_list)', 0, '>' )
    ->leftJoin( 'modx_vkrklient','modx_vkrklient.id', '=', 'modx_vkrzakaz.kli_zak' )
    ->leftJoin( 'modx_vkravtor' ,'modx_vkravtor.id' , '=', 'modx_vkrzakaz.avt_zak' )
    ->leftJoin( 'modx_vkrvidzak','modx_vkrvidzak.id', '=', 'modx_vkrzakaz.vid_zak' )
        
    ->process( $_POST )
    ->json();

I'd try use ->where( function too, it don't help me.

->where( function ( $q ) use ( $cur_id ) {
 $q->where('modx_vkrzakaz.avt_zak',$cur_id); 
} )

Thanks for any advice.

Vitaliy.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin
    Answer ✓

    You would need to use a closure function in order to execute a function since the Editor where method will automatically bind the values given which is not what you want here.

    You might use something like:

    ->where( function ( $q ) use ( $my_id ) {
      $q->where( 'LOCATE("'+$my_id+'", modx_vkrzakaz.avt_list)', 0, '>', false )
    } )
    

    Allan

  • VitalizVitaliz Posts: 71Questions: 7Answers: 1

    try to use a closure function as you write but get old the same error:

    SQLSTATE[42S22]: Column not found: 1054 Unknown column '3' in 'where clause'", data: []

    (then $my_id=3)

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    Could you narrow it down so we know for certain which of the two where statements is causing this issue? i.e. remove one, then the other.

    Allan

This discussion has been closed.