Mjoin does not work using datatable field instead of checkbox

Mjoin does not work using datatable field instead of checkbox

GargiucnGargiucn Posts: 109Questions: 30Answers: 0
editor field with checkbox: (it works)
{
    label: "Mansioni",
    name: "mansioni[].man_id",
    type: "checkbox"
}

editor field with datatable: (does not work)
{
    label: "Mansioni",
    name: "mansioni[].man_id",
    type: "datatable"
}

$editor->join(
    Mjoin::inst( 'mansioni' )
        ->link( 'dipendenti.dip_id', 'dipmans.dip_id' )
        ->link( 'mansioni.man_id', 'dipmans.man_id' )
        ->order( 'man_descr asc' )
        ->fields(
            Field::inst( 'man_id' )
                ->validator( Validate::required() )
                ->options( Options::inst()
                    ->table( 'mansioni' )
                    ->value( 'man_id' )
                    ->label( ['man_descr', 'man_cod'] )
                    ->render( function ( $row ) {
                        return $row['man_descr'].' ('.$row['man_cod'].')';
                    } ) 
                ),
            Field::inst( 'man_descr' ), 
            Field::inst( 'man_cod' )
        )
);  
table dipendenti
dip_id (AUTO INCREMENT) 
dip_name = "NAME SURNAME"

table mansioni
man_id (AUTO INCREMENT)
man_cod = "ADML"
man_descr = "addetto al mulino"

table dipmans
dip_id (from table dipendenti)
man_id (from table mansioni)

foreign keys table dipmans
ADD CONSTRAINT `fk1` FOREIGN KEY (`dip_id`) REFERENCES `dipendenti` (`dip_id`) 
ON DELETE CASCADE ON UPDATE RESTRICT;

ADD CONSTRAINT `fk2` FOREIGN KEY (`man_id`) REFERENCES `mansioni` (`man_id`) 
ON DELETE CASCADE ON UPDATE RESTRICT;

Any advice? thanks,
Giuseppe

Answers

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

    It should do, as shown in this example.

    Can you give me a link to your page so I can take a look and see what is going wrong please?

    Thanks,
    Allan

  • GargiucnGargiucn Posts: 109Questions: 30Answers: 0

    Works perfectly in the following case:

    {
        label: "Autorizzazioni",
        name: "utetipo[].tip_sigla",
        type: 'datatable'
    }   
    

        $editor->join(
            Mjoin::inst( 'utetipo' )
                ->link( 'utemenu.men_id', 'utemenuauth.men_id' )
                ->link( 'utetipo.tip_sigla', 'utemenuauth.tip_sigla' )
                ->order( 'tip_descr asc' )
                ->fields(
                    Field::inst( 'tip_sigla' )
                        ->validator( Validate::required() )
                        ->options( Options::inst()
                            ->table( 'utetipo' )
                            ->value( 'tip_sigla' )
                            ->label( ['tip_descr', 'tip_sigla'] )
                            ->render( function ( $row ) {
                                return $row['tip_descr'].' ('.$row['tip_sigla'].')';
                            } )                             
                        ),
                    Field::inst( 'tip_sigla' ), 
                    Field::inst( 'tip_descr' )
                )
        );  
    
    table utemenu
    men_id (AUTO INCREMENT)
    men_descr = "MENU NAME"
    
    table utetipo
    tip_id (AUTO INCREMENT)
    tip_sigla = "READ"
    tip_descr = "readonly user"
    
    table utemenuauth
    men_id (from table utemenu)
    tip_sigla (from table utetipo)
    

    The only difference is that I use the tip_sigla field instead of tip_id (as if I used man_cod instead of man_id in the previous case).
    I use man_id because I would like the relationships between the tables not to change even if I were to change the value of man_cod.

    Giuseppe

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

    Hi Giuseppe,

    Can you give me a link to a page showing the issue please?

    Thanks,
    Allan

Sign In or Register to comment.