0

我的问题扩展了之前发布的CakePHP:Limit Fields associated with a model。我使用此解决方案有效地通过此调用限制父表的返回字段

$data = $this->SOP10100->find('all', 
        array('fields' => $this->SOP10100->defaultFields));

但是,此方法返回过滤的父字段和未过滤的子字段。我有 131 个子字段,其中我只需要 7 个。我在子表中有相同的 defaultFields 数组构造。如何修改此调用(或创建一个新调用),它将返回同一数组中父模型和子模型的过滤字段?

以下是父表数组的结构:

    public $defaultFields = array(
    'SOP10100.SOPNUMBE',
    'SOP10100.INVODATE',
    'SOP10100.DOCDATE',
    'SOP10100.DOCAMNT',
    'SOP10100.SUBTOTAL');

感谢您的帮助。

4

1 回答 1

1

分数!哇,一天解决了两个大问题。我终于在许多资源的帮助下弄清楚了:

    $this->InvoiceHeader->Behaviors->attach('Containable');
    $data = $this->InvoiceHeader->find('all', array(
        'fields' => $this->InvoiceHeader->defaultFields,
        'contain' => array(
            'InvoiceDetail' => array(
               'fields' => $this->InvoiceDetail->defaultFields))
            )
    );

就像我想要的那样返回我的数组数据:

array(
(int) 0 => array(
    'InvoiceHeader' => array(
        'SOPNUMBE' => 'SVC0202088           ',
        'INVODATE' => '2012-04-17 00:00:00',
        'DOCDATE' => '2012-04-17 00:00:00',
        'DOCAMNT' => '.00000',
        'SUBTOTAL' => '.00000'
    ),
    'InvoiceDetail' => array(
        (int) 0 => array(
            'ITEMNMBR' => 'SERVICE                        ',
            'QUANTITY' => '1.00000',
            'UOFM' => 'EA       ',
            'UNITPRCE' => '.00000',
            'TAXAMNT' => '.00000',
            'CONTSTARTDTE' => '2012-04-17 00:00:00',
            'CONTENDDTE' => '2012-04-30 00:00:00',
            'SOPNUMBE' => 'SVC0202088           '
        ),
于 2012-04-25T22:36:27.283 回答