CodeIgniter DataMapper无法建立树表的关系


CodeIgniter DataMapper Unable To Relate tree tables

我有树表:

CREATE TABLE `bairros` (
    `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
    `cidade_id` INT(11) UNSIGNED NULL DEFAULT NULL,
    PRIMARY KEY (`id`),
    INDEX `FK_bairros_cidades` (`cidade_id`),
    CONSTRAINT `FK_bairros_cidades` FOREIGN KEY (`cidade_id`) REFERENCES `cidades` (`id`)
)
CREATE TABLE `cidades` (
    `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
    `estado_id` TINYINT(4) UNSIGNED NULL DEFAULT NULL,
    PRIMARY KEY (`id`),
    INDEX `FK_cidades_estados` (`estado_id`),
CONSTRAINT `FK_cidades_estados` FOREIGN KEY (`estado_id`) REFERENCES `estados` (`id`)
)
CREATE TABLE `estados` (
    `id` TINYINT(4) UNSIGNED NOT NULL AUTO_INCREMENT,
    PRIMARY KEY (`id`)
)

在我的Bairros类中,我有一个函数:

public function get_by_id($bairro_id)
{
    $bairro = new Bairro();
    $bairro->include_related('cidade');
    $bairro->include_related('estado');
    return $bairro->get_by_id($bairro_id);
}

在我的模型中,我有:

Bairro模型:

var $has_one = array(
    'cidade' => array(
        'class' => 'cidade',
        'other_field' => 'bairro',
        'join_other_as' => 'cidade',
        'join_table' => 'bairros'
    )

Cidade模型:

var $has_one = array(
    'estado' => array(
        'class' => 'estado',
        'other_field' => 'cidade',
        'join_other_as' => 'estado',
        'join_table' => 'cidades'
    )
);
var $has_many = array(
    'bairro' => array(
        'class' => 'bairro',
        'other_field' => 'cidade',
        'join_self_as' => 'cidade',
        'join_table' => 'bairros'
    )
);

Estado模型

var $has_many = array(
    'cidade' => array(
        'class' => 'cidade',
        'other_field' => 'estado',
        'join_self_as' => 'estado',
        'join_table' => 'cidades'
    )
);

我想生产这样的产品:

SELECT bairros.*, cidades.*, estados.*
FROM bairros
LEFT OUTER
JOIN cidades ON cidades.id = bairros.cidade_id
LEFT OUTER
JOIN estados ON estados.id = cidades.estado_id
WHERE bairros.id = 1;

我收到这个消息:

"无法将bairro与estado关联。"

我怎么能这么做?

已解决:

$pedido->include_related('cidade/estado');

因此工作正常。感谢