Модель использует MySQL view и некоторые поля не на одном уровне / hiearchy

Я настроил модель для использования вида. При запросе этого представления в моем контроллере возвращенный набор записей имеет два поля, которые не находятся на том же уровне / уровне, что и остальные.

В этом случае см. ast (asset_id and asset_configuration_id),

Запрашивая представление вручную в dbForge, я получаю плоский набор записей. Я не могу понять, почему это происходит.

Модель:

<?php
App::uses('AppModel', 'Model');

class AssetConfigurationDeploymentStatus extends AppModel {
public $useTable = "asset_configuration_deployment_statuses";

}
?>

Запрос для представления asset_configuration_deployment_statuses:

SELECT `ac`.`id` AS `asset_configuration_id`
, `ast`.`id` AS `asset_id`
, `ac`.`domain_id` AS `domain_id`
, `ac`.`server_id` AS `server_id`
, `e`.`acronym` AS `environment`
, `e`.`id` AS `environment_id`
, `d`.`name` AS `domain`
, `lds`.`deployed_by` AS `last_deployed_by`
, `lds`.`deployed_date` AS `last_deployed_date`
, `lds`.`revision` AS `last_deployed_revision`
, `lds`.`is_failed` AS `last_deployed_is_failed`
, `lss`.`deployed_by` AS `last_successful_deployed_by`
, `lss`.`deployed_date` AS `last_successful_deployed_date`
, `lss`.`revision` AS `last_successful_deployed_revision`
, `lss`.`is_failed` AS `last_successful_deployed_is_failed`
, `eds`.`count_failed_deployments` AS `count_failed_deployments`
, `er`.`last_successful_environment_revision` AS `last_successful_environment_revision`
, `ast`.`asset_group_id` AS `asset_group_id`
FROM
(((((((((`assets` `ast`
JOIN `asset_configurations` `ac`
ON ((`ast`.`id` = `ac`.`asset_id`)))
JOIN `last_deployment_statuses` `lds`
ON ((`ac`.`id` = `lds`.`asset_configuration_id`)))
JOIN `last_successful_deployment_statuses` `lss`
ON ((`ac`.`id` = `lss`.`asset_configuration_id`)))
JOIN `last_environment_deployment_statuses` `eds`
ON ((`ac`.`id` = `eds`.`asset_configuration_id`)))
JOIN `domains` `d`
ON ((`ac`.`domain_id` = `d`.`id`)))
JOIN `servers` `s`
ON ((`ac`.`server_id` = `s`.`id`)))
JOIN `environments_servers` `es`
ON ((`s`.`id` = `es`.`server_id`)))
JOIN `environments` `e`
ON ((`es`.`environment_id` = `e`.`id`)))
JOIN `last_successful_environment_deployment_revision` `er`
ON (((`ac`.`asset_id` = `er`.`asset_id`) AND (`e`.`id` = `er`.`environment_id`))))

Код контроллера:

...

$this->loadModel("AssetConfigurationDeploymentStatus");
$all_deploy_items = $this->AssetConfigurationDeploymentStatus->find('all', array(
'order'=>array('AssetConfigurationDeploymentStatus.environment_id','AssetConfigurationDeploymentStatus.domain'),
'conditions' => array('AssetConfigurationDeploymentStatus.asset_id' => $id)
)
);

foreach($all_deploy_items as $conf){

var_dump($conf);
exit;
...
}

...

Вывод дампа:

array (size=2)
'AssetConfigurationDeploymentStatus' =>
array (size=16)
'asset_configuration_id' => string '172' (length=3)
'domain_id' => string '21' (length=2)
'server_id' => string '10' (length=2)
'environment' => string 'DEV' (length=3)
'environment_id' => string '4' (length=1)
'domain' => string 'my.domain.here' (length=28)
'last_deployed_by' => string 'user' (length=7)
'last_deployed_date' => string '2014-06-23 12:05:24' (length=19)
'last_deployed_revision' => string '644' (length=3)
'last_deployed_is_failed' => boolean false
'last_successful_deployed_by' => string 'user' (length=7)
'last_successful_deployed_date' => string '2014-06-23 12:05:24' (length=19)
'last_successful_deployed_revision' => string '644' (length=3)
'last_successful_deployed_is_failed' => boolean false
'count_failed_deployments' => string '0' (length=1)
'last_successful_environment_revision' => string '1930' (length=4)
'ast' =>
array (size=2)
'asset_id' => string '47' (length=2)
'asset_group_id' => string '28' (length=2)

0

Решение

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

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

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

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector