首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jquery DataTables -将表与查找表连接起来

Jquery DataTables -将表与查找表连接起来
EN

Stack Overflow用户
提问于 2019-10-29 04:08:35
回答 1查看 83关注 0票数 0

我有一个查找(或链接)表learning_event_presentation_lookup

代码语言:javascript
复制
+---------------------------------------+-------------------+-----------------+
| learning_event_presentation_lookup_pk | learning_event_fk | presentation_fk |
+---------------------------------------+-------------------+-----------------+

这是为了方便连接表learning_eventpresentation

在下面的代码中,我需要在联接中使用该表。

目前,我正在收到错误:

DataTables警告:表id=learning_event_table -发生了id=learning_event_table错误: SQLSTATE42000:语法错误或访问冲突: 1066非唯一表/别名:“learning_event”

代码语言:javascript
复制
$( '#learning_event_table' ).DataTable( {
                ajax: "program_data/learning_event_data.php",
                dom: "Bfrtip",
                columns: [ {
                    data: "learning_event.learning_event_name"
                }, {
                    data: "learning_event.learning_event_outcome"
                }, {
                    data: "rdb_group.rdb_group_name"
                }, {
                    data: "presentation.presentation_name"
                }, {
                    data: "rotation_discipline_block.rotation_discipline_block_name"
                } ],
                select: {
                    style: 'os',
                    selector: 'td:first-child'
                },
                buttons: [ {
                    extend: "create",
                    editor: editor
                }, {
                    extend: "edit",
                    editor: editor
                }, {
                    extend: "remove",
                    editor: editor
                } ]
            } );

代码语言:javascript
复制
Editor::inst( $db2, 'learning_event', 'learning_event_pk' )   
    ->field(
     Field::inst( 'learning_event.learning_event_name' ),
     Field::inst( 'learning_event.learning_event_outcome' ),
    Field::inst( 'presentation.presentation_name' ),
     Field::inst( 'learning_event.rdb_group_fk' )
            ->options( Options::inst()
                ->table( 'rdb_group' )
                ->value( 'rdb_group_pk' )
                ->label( 'rdb_group_name' )
            )
            ->validator( 'Validate::notEmpty' ),
        Field::inst( 'rdb_group.rdb_group_name' ),
        Field::inst( 'learning_event.rotation_discipline_block_fk' )
            ->options( Options::inst()
                ->table( 'rotation_discipline_block' )
                ->value( 'rotation_discipline_block_pk' )
                ->label( 'rotation_discipline_block_name' )
            )
            ->validator( 'Validate::dbValues' ),
        Field::inst( 'rotation_discipline_block.rotation_discipline_block_name' )

    )
    ->leftJoin( 'rdb_group', 'rdb_group.rdb_group_pk', '=', 'learning_event.rdb_group_fk' )
    ->leftJoin( 'rotation_discipline_block', 'rotation_discipline_block.rotation_discipline_block_pk', '=', 'learning_event.rotation_discipline_block_fk' )
    ->leftJoin( 'presentation', 'presentation.presentation_pk', '=', 'learning_event_presentation_lookup.presentation_fk' )
    ->leftJoin( 'learning_event', 'learning_event.learning_event_pk', '=', 'learning_event_presentation_lookup.learning_event_fk' )
    ->process($_POST)
    ->json();
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-10-29 04:46:34

好的,我查看了关于使用链接表的文档:

https://editor.datatables.net/examples/advanced/joinLinkTable.html

所以现在我有了以下内容,它没有产生任何错误,而且工作正常。不过,用dataTables格式进行联接并不是很直观.

代码语言:javascript
复制
Editor::inst( $db2, 'learning_event', 'learning_event_pk' )   
    ->field(
     Field::inst( 'learning_event.learning_event_name' ),
     Field::inst( 'learning_event.learning_event_outcome' ),
    Field::inst( 'presentation.presentation_name' ),
     Field::inst( 'learning_event.rdb_group_fk' )
            ->options( Options::inst()
                ->table( 'rdb_group' )
                ->value( 'rdb_group_pk' )
                ->label( 'rdb_group_name' )
            )
            ->validator( 'Validate::notEmpty' ),
        Field::inst( 'rdb_group.rdb_group_name' ),
        Field::inst( 'learning_event.rotation_discipline_block_fk' )
            ->options( Options::inst()
                ->table( 'rotation_discipline_block' )
                ->value( 'rotation_discipline_block_pk' )
                ->label( 'rotation_discipline_block_name' )
            )
            ->validator( 'Validate::dbValues' ),
        Field::inst( 'rotation_discipline_block.rotation_discipline_block_name' )

    )
    ->leftJoin( 'rdb_group', 'rdb_group.rdb_group_pk', '=', 'learning_event.rdb_group_fk' )
    ->leftJoin( 'rotation_discipline_block', 'rotation_discipline_block.rotation_discipline_block_pk', '=', 'learning_event.rotation_discipline_block_fk' )
    ->leftJoin( 'learning_event_presentation_lookup', 'learning_event.learning_event_pk', '=', 'learning_event_presentation_lookup.learning_event_fk' )
    ->leftJoin( 'presentation', 'learning_event_presentation_lookup.presentation_fk', '=', 'presentation.presentation_pk' )
    ->process($_POST)
    ->json();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58601327

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档