NOTORM Join возвращает ноль

я столкнулся с проблемой с моим Slim — Rest — API, и единственное, что осталось, это вопросительные знаки над моей головой.

Я присоединился к нескольким таблицам уже в моем API, который работал нормально:

// Detail View of Task
$app->get('/task_detail/:id', function($id) use ($app, $db) {
$task_data_array = array();
foreach ($db->task()->where('task_id', $id) as $task) {
$task_data_array[] = array(
'task_id' => $task['task_id'],
'task_date' => $task['task_date'],
'task_deadline' => $task['task_deadline'],
'target_snr' => $task['target_snr'],
'client_name' => $task->client['client_name'],
'client_adress' => $task->client['client_adress'],
'client_zip' => $task->client['client_zip'],
'client_contact' => $task->client['client_contact'],
'workflow_id' => $task['workflow_id'],
'task_type' => $task->task_type['task_type'],
'task_desc' => $task->task_type['task_desc'],
'status' => $task['status']
);
}
$app->response()->header('Content-Type', 'application/json;charset=utf-8');
echo json_encode($task_data_array);
});

Вернуть:

[{"task_id":"1","task_date":"2016-06-15","task_deadline":"2016-06-30 11:00:00.000000","target_snr":"12523452343","client_name":"Stahlbau AG","client_adress":"Stahlbruch 40","client_zip":"48881","client_contact":"[email protected]","workflow_id":"1","task_type":"blabla","task_desc":"blabla","status":"Open"}]

Здесь я соединяю свою таблицу задач с таблицей client и task_type. Работает нормально.

НО:

Теперь у меня есть два примера, где соединение не работает и возвращает только «ноль» как объединенные значения:

Код:

// Workflow for Detail
$app->get('/workflow_detail/:id', function($id) use ($app, $db) {
$workflow_data_array = array();
foreach ($db->workflow()->where('workflow_id', $id) as $workflow_detail) {
$workflow_data_array[] = array(
'workflow_id' => $workflow_detail['workflow_id'],
'workflow_name' => $workflow_detail['workflow_name'],
'workflow_desc' => $workflow_detail['workflow_desc'],
'product_id' => $workflow_detail->product['product_id'],
'product_type' => $workflow_detail->product['product_type'],
'product_name' => $workflow_detail->product['product_name'],
'list_category_id' => $workflow_detail->list_category['list_category_id'],
'list_category_desc' => $workflow_detail->list_category['list_category_desc']
);
$app->response()->header('Content-Type', 'application/json;charset=utf-8');
echo json_encode($workflow_data_array);
}
});

Возвращает:

[{"workflow_id":"2","workflow_name":"Reparatur","workflow_desc":"blabla","product_id":"2","product_type":null,"product_name":null,"list_category_id":"1004","list_category_desc":"Hardware-Tausch"}]

Та же проблема у меня с другой:

$app->get('/task_solution/:id', function($id) use ($app, $db) {
$solution_array = array();
foreach ($db->task_list_solution()->where('task_id',$id) as $solution) {
$solution_array[] = array(
'task_id' => $solution['task_id'],
'list_catalog_id' => $solution['list_catalog_id'],
'list_catalog_task' => $solution->list_catalog['list_catalog_task'],
'list_catalog_desc' => $solution->list_catalog['list_catalog_desc'],
'task_date' => $solution->task['task_date'],
'target_snr' => $solution->task['target_snr']
);
$app->response()->header('Content-Type', 'application/json;charset=utf-8');
echo json_encode($solution_array);
}
});

Возвращает:

[{"task_id":"1","list_catalog_id":"11","list_catalog_task":"Akku Aufschrauben","list_catalog_desc":"Akkufach aufschrauben. Dafuer 13 Schrauben entfernen blabla","task_date":null,"target_snr":null}]

Я уже пробовал кое-что, но ничего не получается. Я не понимаю, почему он работает над одной частью, а не над этими частями ..

Вот моя структура NOTORM и структура таблицы, которую я использую:

$structure = new NotORM_Structure_Discovery($pdo, $cache = null, $foreign = '%s_id');

Таблица рабочих процессов:

-- -----------------------------------------------------
-- Table `itec_app_workflow`.`workflow`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `itec_app_workflow`.`workflow` (
`workflow_id` INT NOT NULL AUTO_INCREMENT,
`workflow_name` VARCHAR(100) NULL,
`workflow_desc` VARCHAR(150) NULL,
`workflow_adv_desc` VARCHAR(150) NULL,
`product_id` INT NOT NULL,
`list_category_id` INT NOT NULL,
PRIMARY KEY (`workflow_id`, `product_id`, `checklist_category_id`),
INDEX `fk_workflow_produkt1_idx` (`product_id` ASC),
INDEX `fk_workflow_checklist1_idx` (`list_category_id` ASC),
CONSTRAINT `fk_workflow_produkt1`
FOREIGN KEY (`product_id`)
REFERENCES `itec_app_workflow`.`product` (`product_id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_workflow_checklist1`
FOREIGN KEY (`list_category_id`)
REFERENCES `itec_app_workflow`.`list_category` (`list_category_id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;

Таблица продуктов:

-- -----------------------------------------------------
-- Table `itec_app_workflow`.`product`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `itec_app_workflow`.`product` (
`product_id` INT NOT NULL AUTO_INCREMENT,
`product_name` VARCHAR(100) NULL,
`product_type` VARCHAR(45) NULL,
`manu_id` INT NOT NULL,
PRIMARY KEY (`product_id`, `manu_id`),
INDEX `fk_produkt_hersteller1_idx` (`manu_id` ASC),
CONSTRAINT `fk_produkt_hersteller1`
FOREIGN KEY (`manu_id`)
REFERENCES `itec_app_workflow`.`manufacturer` (`manu_id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;

Task_list_solution, list_catalog и задача:

-- -----------------------------------------------------
-- Table `itec_app_workflow`.`task`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `itec_app_workflow`.`task` (
`task_id` INT NOT NULL AUTO_INCREMENT,
`task_date` DATE NULL,
`task_deadline` DATETIME(6) NULL,
`target_snr` VARCHAR(45) NULL,
`client_id` INT NOT NULL,
`tech_id` INT NOT NULL,
`workflow_id` INT NOT NULL,
`task_type_id` INT NOT NULL,
PRIMARY KEY (`task_id`, `client_id`, `tech_id`, `workflow_id`, `task_type_id`),
INDEX `fk_auftrag_kunden1_idx` (`client_id` ASC),
INDEX `fk_auftrag_techniker1_idx` (`tech_id` ASC),
INDEX `fk_auftrag_workflow1_idx` (`workflow_id` ASC),
INDEX `fk_auftrag_auftrags_typ1_idx` (`task_type_id` ASC),
CONSTRAINT `fk_auftrag_kunden1`
FOREIGN KEY (`client_id`)
REFERENCES `itec_app_workflow`.`client` (`client_id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_auftrag_techniker1`
FOREIGN KEY (`tech_id`)
REFERENCES `itec_app_workflow`.`tech` (`tech_id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_auftrag_workflow1`
FOREIGN KEY (`workflow_id`)
REFERENCES `itec_app_workflow`.`workflow` (`workflow_id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_auftrag_auftrags_typ1`
FOREIGN KEY (`task_type_id`)
REFERENCES `itec_app_workflow`.`task_type` (`type_id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `itec_app_workflow`.`list_catalog`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `itec_app_workflow`.`list_catalog` (
`list_catalog_id` INT NOT NULL AUTO_INCREMENT,
`list_catalog_task` VARCHAR(150) NULL,
`list_catalog_desc` VARCHAR(150) NULL,
PRIMARY KEY (`list_catalog_id`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `itec_app_workflow`.`task_list_solution`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `itec_app_workflow`.`task_list_solution` (
`task_list_solution_id` INT NOT NULL AUTO_INCREMENT,
`task_list_solution_answer` TINYINT(1) NULL,
`list_catalog_id` INT NOT NULL,
`task_id` INT NOT NULL,
PRIMARY KEY (`task_list_solution_id`, `list_catalog_id`, `task_id`),
INDEX `fk_auftr_checklist_solution_check_katalog1_idx` (`list_catalog_id` ASC),
INDEX `fk_auftr_checklist_solution_auftrag1_idx` (`task_id` ASC),
CONSTRAINT `fk_auftr_checklist_solution_check_katalog1`
FOREIGN KEY (`list_catalog_id`)
REFERENCES `itec_app_workflow`.`list_catalog` (`list_catalog_id`)
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT `fk_auftr_checklist_solution_auftrag1`
FOREIGN KEY (`task_id`)
REFERENCES `itec_app_workflow`.`task` (`task_id`)
ON DELETE CASCADE
ON UPDATE CASCADE)
ENGINE = InnoDB;

Я очень надеюсь, что вы, ребята, сможете мне помочь.

Кстати: Join в PHPMYADMIN работает нормально (без нуля), его НОРМА, но я не понимаю, почему.

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]