Jquery DataTables-将表与查找表连接
我有一个查找(或链接)表Jquery DataTables-将表与查找表连接,jquery,mysql,datatables,Jquery,Mysql,Datatables,我有一个查找(或链接)表learning\u event\u presentation\u lookup: +---------------------------------------+-------------------+-----------------+ | learning_event_presentation_lookup_pk | learning_event_fk | presentation_fk | +-----------------------------------
learning\u event\u presentation\u lookup
:
+---------------------------------------+-------------------+-----------------+
| learning_event_presentation_lookup_pk | learning_event_fk | presentation_fk |
+---------------------------------------+-------------------+-----------------+
这是为了方便连接表学习\u事件
和演示
在下面的代码中,我需要在联接中使用该表
目前,我得到了一个错误:
DataTables警告:table id=learning_event_table-发生SQL错误:SQLSTATE[42000]:语法错误或访问冲突:1066非唯一表/别名:“learning_event”
及
好的,我查看了关于使用链接表的文档: 因此,现在我有以下内容,它不会产生任何错误,并且工作正常。但是,以dataTables格式进行连接并不直观
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();
如果您将其作为sql,您可以找到它。上面说,
learning\u event
以相同的名称加入了两次。
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();
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();