Turn Mjoin a required field

Turn Mjoin a required field

itarodrigoitarodrigo Posts: 15Questions: 6Answers: 0

I have the code

->join(
        Mjoin::inst('tb_perfil')
        ->link('tb_usuario.id', 'rl_usuario_perfil.usuario_id')
        ->link('tb_perfil.id', 'rl_usuario_perfil.perfil_id')
        ->fields(
            Field::inst('id')
            ->validator('Validate::required'),
            Field::inst('descricao')
        )
    )

But this field is not required on the register. How to set the Mjoin filter to be required?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Use the mjoinMinCount validator.

    Allan

  • itarodrigoitarodrigo Posts: 15Questions: 6Answers: 0

    This works:

    ->join(
            Mjoin::inst('tb_perfil')
            ->validator('tb_perfil[].id', Validate::mjoinMinCount(1))
            ->link('tb_usuario.id', 'rl_usuario_perfil.usuario_id')
            ->link('tb_perfil.id', 'rl_usuario_perfil.perfil_id')
            ->fields(
                Field::inst('id')
                ->validator('Validate::required'),
                Field::inst('descricao')
            )
        )
    

    But this not works:

    ->join(
            Mjoin::inst('tb_perfil')
            ->validator('tb_perfil[].id', Validate::mjoinMinCount(1,
                ValidateOptions::inst()
                    ->message('Campo obrigatório!')
                )
            )
            ->link('tb_usuario.id', 'rl_usuario_perfil.usuario_id')
            ->link('tb_perfil.id', 'rl_usuario_perfil.perfil_id')
            ->fields(
                Field::inst('id')
                ->validator('Validate::required'),
                Field::inst('descricao')
            )
        )
    

    The code not show any error, but not works. How to create a custom messagem?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    The two Mjoin validators actually don't take a ValidateOptions class as their second parameter - it is just a string:

    Validate::mjoinMinCount(1, 'Campo obrigatório!')
    

    should do it.

    Allan

Sign In or Register to comment.