Я пытался решить проблему самостоятельного левого соединения в библиотеке ignated datatables с использованием псевдонима. Любая идея, пожалуйста?
Моя структура категорий таблиц:
id_categories | name_categories | description_categories | icon_categories | slug_categories | parent_categories | sub_parent_categories
1 | monitor | this is monitor | monitor.png | monitor | 0 | 0
2 | curved | this is monitor curved | monitorcurved.png | curved | 1 | 0
3 | tube | this is monitor tube | monitortube.png | tube | 1 | 0
4 | 21" | this is monitor curved 21"| monitorcurved21.png | 21-inc | 1 | 2
В контроллере:
$this->datatables->select("t1.id_categories AS t1id, t1.name_categories AS t1name, t2.id_categories AS t2id, t2.name_categories AS t2name, t3.id_categories AS t3id, t3.name_categories AS t3name, t1.description_categories, t1.icon_categories, t1.slug_categories");
$this->datatables->from('categories t1');
$this->datatables->join('categories t2','t2.parent_categories = t1id','left');
$this->datatables->join('categories t3','t3.sub_parent_categories = t1id','left');
return $this->datatables->generate();
В представлении:
{data: "t1id", width: '5%', className: 'text-center', orderable: false},
{data: "t1.name_categories"},
{data: "t1.description_categories"},
{data: "t1.icon_categories", className: "text-center", searchable: false, orderable: false, render: function(data){
return '<a href="<?= base_url("upload/categories/") ?>'+data+'"><img src="<?= base_url("upload/categories/") ?>'+data+'" height=75 width=75></a>'
}},
{data: "t1.slug_categories"},
{data: "t2name", className: "text-center", searchable: false, orderable: false, render: function(data){
if (data == 0){
return "-"
} else {
return "ei"
}
}},
{data: "t3name"},
{data: "t1.status_categories", width: '20%', searchable: false, className: 'text-center', render: function(data){
if(data == '1') return 'Active'
else return 'Not Active'
}},
{name: "t1id", data: "tid", width: '15%', searchable: false, orderable: false, className: 'text-center', render: function(data){
return '<a title="Edit Data" href="javascript:void(0);" data-id='+data+' class="edit btn btn-success btn-sm"><i class="fa fa-edit"></i></a> <a title="Delete Data" href="javascript:void(0);" data-id='+data+' class="delete btn btn-danger btn-sm"><i class="fa fa-trash"></i></a>'
}}
и я получаю эту ошибку
Error Number: 1054
Unknown column 't1id' in 'on clause'
SELECT `t1`.`id_categories` AS `t1id`, `t1`.`name_categories` AS `t1name`, `t2`.`id_categories` AS `t2id`, `t2`.`name_categories` AS `t2name`, `t3`.`id_categories` AS `t3id`, `t3`.`name_categories` AS `t3name`, `t1`.`description_categories`, `t1`.`icon_categories`, `t1`.`slug_categories`
FROM `categories` AS `t1`
LEFT JOIN `categories` `t2` ON `t2`.`parent_categories` = `t1id`
LEFT JOIN `categories` `t3` ON `t3`.`sub_parent_categories` = `t1id`
ОБНОВЛЕНИЕ:
затем, когда я меняю код при соединении:
t2.parent_categories = t1id
t3.sub_parent_categories = t1id
на:
t2.parent_categories = id_categories
t3.sub_parent_categories = id_categories
Я получил ошибку:
Duplicate column name 'id_categories'
SELECT COUNT(*) FROM (SELECT *
FROM `categories` `t1`
LEFT JOIN `categories` `t2` ON `t2`.`parent_categories` = `t1`.`id_categories`
LEFT JOIN `categories` `t3` ON `t3`.`sub_parent_categories` = `t1`.`id_categories`) SqueryAux