Cakephp 2.0我使用的是HABTM关系,但中间表模型没有获取关联数据

时间:2012-08-18 06:29:18

标签: cakephp cakephp-2.0

例如我有招标表和财团表,而对于HABTM,我创建了中间表tenders_consortiums。现在根据我的要求,我创建了一个模型TendersConsortium

class TendersConsortium extends AppModel {

/**
 * Use table
 * @var mixed False or table name
 */
public $useTable = 'tenders_consortiums';

/**
 * Display field
 * @var string
 */
public $displayField = 'counsortium_id';

//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
 * belongsTo associations
 * @var array
 */
public $belongsTo = array(
    'Tender' => array(
        'className' => 'Tender',
        'foreignKey' => 'tender_id',
        'conditions' => '',
        'fields' => '',
        'order' => ''
    ),
    'Counsortium' => array(
        'className' => 'Counsortium',
        'foreignKey' => 'counsortium_id',
        'conditions' => '',
        'fields' => '',
        'order' => ''
    )
);

}

但是当我获取分页数据$this->paginate('TendersConsortium', $TendersConsortium_cond)时,它会返回

array(
    (int) 0 => array(
        'TendersConsortium' => array(
            'id' => '6',
            'tender_id' => '3',
            'consortium_id' => '3',
            'state' => 'Winner',
            'created' => '2012-08-08 12:21:28'
        )
    ),
    (int) 1 => array(
        'TendersConsortium' => array(
            'id' => '7',
            'tender_id' => '3',
            'consortium_id' => '1',
            'state' => 'Winner',
            'created' => '2012-08-08 12:21:28'
        )
    )
)

我还设置了递归级别2,但没有从投标和联盟表中获取相关数据。