Mjoin not working

Mjoin not working

rossbobrossbob Posts: 29Questions: 4Answers: 0

Hi There,

No matter what I do, I can't get the Mjoin to work the way I think it should work. I've looked at examples but the error message I'm getting;

sError: "Join was performed on the field 'master_id' which was not included in the Editor field list. The join field must be included as a regular field in the Editor instance."

Does not make any sense to me. My tables are structured like so;

Main table
id
...
dbDateTime


Notes Table
id (pri)    int
master_id (id on Main Table)    int
user_id (id on Users Table) int
note_text   text
dbDateTime  datetime

Users Table
id (pri) int
name varchar
...
dbDateTime

My join code looks like this;

    $response = Editor::inst($db, 'unmatched_invoices_master')
        //->debug(true)
        ->where( 'matched', 'No' )
        ->fields(
            Field::inst('id')
            ...
)
        ->join(
            Mjoin::inst( 'unmatched_invoices_notes' )
                ->link( 'unmatched_invoices_notes.master_id', 'unmatched_invoices_master.id')
                ->link( 'unmatched_invoices_notes.user_id', 'users_table.id')
                ->fields(
                    Field::inst( 'id' )->validator( 'Validate::required' ),
                    Field::inst( 'note_text' ),
                    Field::inst( 'user_id' ),
                    Field::inst( 'name' )
                )
        )
        ->process(array())->json();

What am I doing wrong? I'm sorry if this has been asked before. I have tried to find a fix for this but the forum articles ive found which are similar do not give me a fix which works. If I remove this line;

->link( 'unmatched_invoices_notes.user_id', 'users_table.id')

And

Field::inst( 'name' )

from the Mjoin, the query works and I don't have master_id defined anywhere either. So the error message is a little lost on me.

Thanks for your help.

Ross.

Answers

  • rossbobrossbob Posts: 29Questions: 4Answers: 0

    This is one of the forum artlicles that I attempted to use to figure out the problem. I read through this but do not understand the error message about master_id not being defined in Editor.

    https://datatables.net/forums/discussion/47556/the-join-field-must-be-included-as-a-regular-field-in-the-editor-instance-error

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

    It looks like there might be an error in the .NET libraries there. In theory the order of the parameters for the link() method shouldn't matter, but it looks like they do there.

    Could you try:

                    ->link( 'unmatched_invoices_master.id', 'unmatched_invoices_notes.master_id')
                    ->link('users_table.id', 'unmatched_invoices_notes.user_id')
    

    Thanks,
    Allan

  • rossbobrossbob Posts: 29Questions: 4Answers: 0

    Thanks Allan, im using PHP libraries. I tried your suggestion before reading your response as I wondered if this had something to do with it. In the end, I gave up as Ill give it another go once Ive finished this project. Would be great to get it going. Btw, Ive only just been able to start using Mjoins. For some weird reason, I could only get them to work if I included the following;
    use DataTables\Database,
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;

    Before including the above, I was getting Class not found errors when using Mjoin. Was strange.

This discussion has been closed.