From 7157693d28ba63fb70f5ad11eed1b3d93252c495 Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 26 Mar 2007 16:35:16 +0000 Subject: [PATCH] --- ...tions - Foreign key constraints - Introduction.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/manual/docs/Object relational mapping - Relations - Foreign key constraints - Introduction.php b/manual/docs/Object relational mapping - Relations - Foreign key constraints - Introduction.php index c831c872d..32c52413b 100644 --- a/manual/docs/Object relational mapping - Relations - Foreign key constraints - Introduction.php +++ b/manual/docs/Object relational mapping - Relations - Foreign key constraints - Introduction.php @@ -27,7 +27,11 @@ class Order extends Doctrine_Record } public function setUp() { - $this->hasOne('Product', 'Order.product_id', array('constraint' => true)); + $this->hasOne('Product', 'Order.product_id'); + + // foreign key columns should *always* have indexes + + $this->index('product_id', array('fields' => 'product_id')); } } @@ -36,8 +40,9 @@ When exported the class 'Order' would execute the following sql: CREATE TABLE orders ( order_id integer PRIMARY KEY, - product_no integer REFERENCES products (id), - quantity integer + product_id integer REFERENCES products (id), + quantity integer, + INDEX product_id_idx (product_id) ) Now it is impossible to create orders with product_no entries that do not appear in the products table.