我有這樣關係在模型之間的Yii
+------------------+
| Invoices |
+------------------+
| id |
| customer_id (Fk) |
| description |
+------------------+
+------------------+
| InvoiceItems |
+------------------+
| id |
| Item_name |
| price |
| discount |
| description |
+------------------+
+------------------+
| Customers |
+------------------+
| id |
| firstname |
| lastname |
| description |
+------------------+
數據庫根據我做的模型關係如下數據庫。
發票模型中,關係是這樣的
public function relations()
{
return array(
'invoiceitem' => array(self::HAS_MANY,'InvoiceItems','invoice_id'),
'customers' => array(self::BELONGS_TO,'Customer','customer_id'),
);
}
在InvoiceItems模型關係是這樣的
public function relations()
{
return array(
'invoice' => array(self::BELONGS_TO,'Invoices','invoice_id'),
);
}
在客戶關係模式是這樣的
public function relations()
{
return array(
'invoice' => array(self::HAS_MANY, 'Invoices','customer_id')
);
}
現在我想要知道這些模型之間的關係是否正確?
你的關係是正確的前提是你有外鍵由邁克爾 – 2012-02-21 14:56:09