Mjoin

Mjoin

belubelu Posts: 38Questions: 14Answers: 0
edited December 2019 in Free community support

Hello,

I am trying to perform an MJoin, but I am getting this error, although I have the field in my regular field list...

What do I do wrong?

Thanks in advance!

Error: DataTables warning: table id=table - Join was performed on the field 'user_id' which was not included in the Editor field list. The join field must be included as a regular field in the Editor instance.

Join - Part of my codes

// Build our Editor instance and process the data coming from _POST
$editor = Editor::inst($db, 'as_users as users', 'user_id');

########
# Joins
// für die as_user_details
$editor->leftJoin( 'as_user_details as details', 'users.user_id', '=', 'details.user_id' );

// as_user_roles
$editor->leftJoin('as_user_roles as roles', 'users.user_role', '=', 'roles.role_id');

// Join für den Namen des Users, der dein Eintrag erzeugt hat
$editor->leftJoin('as_user_details as created_details', 'users.created_by_user_id', '=', 'created_details.user_id');

// Join für die Qualifikationen 1:n
$editor->join(
    Mjoin::inst( 'qualifications_names' )
        ->link( 'users.user_id', 'link_as_users__qualifications_names.user_id' )
        ->link( 'qualifications_names.id', 'link_as_users__qualifications_names.qualification_names_id' )
       // ->order( 'name asc' )
        ->fields(
            Field::inst( 'id' )
                ->set(Field::SET_NONE)
               // ->validator( 'Validate::required' )
                ->options( Options::inst()
                    ->table( 'qualifications_names' )
                    ->value( 'id' )
                    ->label( 'qualification_name' ),
                Field::inst( 'qualification_name' )
                )
        )
);

# EO Joins
########
// User_id - wird vielleicht gebraucht
$editor->fields(Field::inst('users.user_id')
        ->set(Field::SET_NONE) // weder beim neu erzeugen, noch beim Update schreiben - wird ja auf DB Ebene automatisch vergeben
    );

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin
    Answer ✓

    Could you try this for the constructor please:

    $editor = Editor::inst($db, 'as_users as users', 'users.user_id');
    

    The other thing to try, if that doesn't resolve it, is to remove the as users alias and update to use as_users.

    Thanks,
    Allan

  • belubelu Posts: 38Questions: 14Answers: 0

    Removing the table alias and using it's real name worked.

    Thanks a lot,
    Bernhard

This discussion has been closed.