1

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":"stahl@stahlbauag.de","workflow_id":"1","task_type":"blabla","task_desc":"blabla","status":"Open"}]

ここでは、タスク テーブルを client および task_type テーブルと結合します。正常に動作しています。

しかし:

ここで、結合が機能せず、結合された値として「null」のみを返す 2 つのサンプルを取得しました。

コード:

// 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}]

私はすでにいくつかのことを試しましたが、何もうまくいかないようです。なぜそれが1つの部分で機能していて、この部分では機能していないのかわかりません..

これが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;

皆さんが私を助けてくれることを本当に願っています。

ところで:PHPMYADMINでの参加は正常に(nullなしで)そのNOTORMで動作していますが、理由はわかりません。

4

0 に答える 0