Mjoin failing to process data

Mjoin failing to process data

kicks66kicks66 Posts: 11Questions: 6Answers: 0

I have the following code:

Editor::inst( $db, 'creators' )
    ->fields(
        Field::inst( 'username' ),
        Field::inst( 'email' )
    )
    ->join(
        Mjoin::inst('creator_lists')
            ->link('creators.id', 'creators_to_list.user_id')
            ->link('creator_lists.id', 'creators_to_list.list_id')
            ->fields(
                Field::inst('id')
                    ->options( Options::inst()
                        ->table( 'creator_lists' )
                        ->value( 'id' )
                        ->label( 'list_name' )
                    ),
                Field::inst('list_name')
            )
    )
    ->join(
        Mjoin::inst('tags')
            ->link('creators.id', 'creator_tags.user_id')
            ->link('tags.id', 'creator_tags.tag_id')
            ->fields(
                Field::inst( 'id' )
                  ->options( Options::inst()
                    ->table( 'tags' )
                    ->value( 'id' )
                    ->label( 'tag' )
                ),
                Field::inst( 'tag' )
            )
    )
    ->process( $_POST )
    ->debug(true)
    ->json();

The "tags" section of this works, however, if I then add in the "creator_lists" section, i can do a "GET" request and read data correctly into my table, however a POST request from the frontend, if i change anything (tags, lists etc), will fail with

Fatal error: Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, string given in /Users/me/Developer/creator-explorer-v2/vendor/datatables.net/editor-php/Editor/Join.php:796 Stack trace: #0 /Users/me/Developer/creator-explorer-v2/vendor/datatables.net/editor-php/Editor/Join.php(796): count('') #1 /Users/me/Developer/creator-explorer-v2/vendor/datatables.net/editor-php/Editor.php(857): DataTables\Editor\Join->validate(Array, Object(DataTables\Editor), Array, 'edit') #2 /Users/me/Developer/creator-explorer-v2/vendor/datatables.net/editor-php/Editor.php(1035): DataTables\Editor->validate(Array, Array) #3 /Users/me/Developer/creator-explorer-v2/vendor/datatables.net/editor-php/Editor.php(707): DataTables\Editor->_process(Array) #4 /Users/me/Developer/creator-explorer-v2/data/creators.php(75): DataTables\Editor->process(Array) #5 /Users/me/Developer/creator-explorer-v2/index.php(30): include('/Users/me...') #6 [internal function]: {closure}() #7 /Users/me/Developer/creator-explorer-v2/vendor/bramus/router/src/Bramus/Router/Router.php(458): call_user_func_array(Object(Closure), Array) #8 /Users/me/Developer/creator-explorer-v2/vendor/bramus/router/src/Bramus/Router/Router.php(440): Bramus\Router\Router->invoke(Object(Closure), Array) #9 /Users/me/Developer/creator-explorer-v2/vendor/bramus/router/src/Bramus/Router/Router.php(287): Bramus\Router\Router->handle(Array, true) #10 /Users/me/Developer/creator-explorer-v2/index.php(38): Bramus\Router\Router->run() #11 {main} thrown in /Users/me/Developer/creator-explorer-v2/vendor/datatables.net/editor-php/Editor/Join.php on line 796

Answers

  • kicks66kicks66 Posts: 11Questions: 6Answers: 0

    Looking at my frontend code, when I add a new creator_list, this is what the datatables frontend is sending;

    data[row_9690][username]: theglownarrative
    data[row_9690][email]:
    data[row_9690][creator_lists]:
    data[row_9690][creator_lists-many-count]: 1
    data[row_9690][tags][0][id]: 24
    data[row_9690][tags-many-count]: 1
    action: edit

    which seems like its sending an empty creator_lists field

  • kicks66kicks66 Posts: 11Questions: 6Answers: 0

    My frontend code has:

    columns: [
    {
    data: 'creator_lists',
    render: {
    _: '[, ].list_name',
    sb: '[].list_name'
    },
    searchBuilder: {
    orthogonal: 'sb'
    },
    searchBuilderType: 'array'
    }

    and var editor = new DataTable.Editor({
    fields: [{
    label: 'Lists',
    name: 'creator_lists[].id',
    type: 'datatable',
    multiple: true
    }

  • kicks66kicks66 Posts: 11Questions: 6Answers: 0

    Ah it seems like a bug!

    If i change creator_lists to creatorLists it works

Sign In or Register to comment.