0

例如,我有投标表和财团表,对于 HABTM,我创建了中间表投标_财团。现在为了我的要求,我创建了一个模型 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,但没有从投标和财团表中获取相关数据。

4

1 回答 1

0

http://book.cakephp.org/2.0/en/models/associations-linking-models-together.html#hasmany-through

有帮助

于 2012-08-20T09:24:53.867 回答