我的问题扩展了之前发布的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');
感谢您的帮助。
答案 0 :(得分:1)
SCORE!哇,一天解决了两个大问题。我终于在许多资源的帮助下找到了它:
$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 '
),