【发布时间】:2015-02-06 12:23:58
【问题描述】:
每个Artikel 恰好有一个Barcode。出于几个原因,我想拆分 Artikel 模型和 Barcode 模型。当我 find() artikel 表中的某些内容时,它会返回一个包含正确条形码部分的数组。但是当我尝试查找条形码时,数组的 artikel 部分为空。
这就是我的意思:
// $this->Artikel->findById(102);
array(
'Artikel' => array(
'id' => '102',
'name' => 'Spätburgunder Spätlese Barrique',
'erzeuger_id' => '679',
'volumen_id' => '44',
'artikelgruppe_id' => '17'
),
'Barcode' => array(
'id' => '1',
'artikel_id' => '102',
'barcode' => '123456'
)
)
// $this->Barcode->findByBarcode(123456);
array(
'Barcode' => array(
'id' => '1',
'artikelnummer' => 'DE51076',
'barcode' => '123456'
),
'Artikel' => array(
'artikelnummer' => null, // this is null
'name' => null, // this is null as well
'erzeuger_id' => null, // also null
'volumen_id' => null, // ……
'artikelgruppe_id' => null // null
)
)
任何想法我做错了什么?
这些是模型
// Barcode.php
public $hasOne = array(
'Artikel' => array(
'className' => 'Artikel',
'foreignKey' => 'artikel_id'
)
);
// Artikel.php
public $hasOne = array(
'Barcode' => array(
'className' => 'Barcode',
'foreignKey' => 'artikel_id'
)
);
【问题讨论】:
-
我认为你必须写一个从 Barcode 到 Artickel 的 belongsTo 关系
标签: php cakephp relationship