Changeset 5287

Show
Ignore:
Timestamp:
12/11/08 15:09:22 (7 months ago)
Author:
romanb
Message:

Removed unfitting doc section that seemed misplaced.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/1.1/docs/manual/en/basic-schema-mapping/record-identifiers.txt

    r4674 r5287  
    88+++ Natural 
    99 
    10 Natural identifier is a property or combination of properties that is unique and non-null. The use of natural identifiers  
    11 is encouraged. 
     10Natural identifier is a property or combination of properties that is unique and non-null. 
    1211 
    1312<code type="php"> 
     
    3130 
    3231+++ Autoincremented 
    33 Autoincrement primary key is the most basic identifier and its usage is strongly encouraged. Sometimes you may want to use  
     32Autoincrement primary key is the most basic identifier. Sometimes you may want to use  
    3433some other name than {{id}} for your autoinc primary key. It can be specified as follows: 
    3534 
     
    5655</code> 
    5756 
    58 You should consider using autoincremented or sequential primary keys only when the record cannot be identified naturally  
    59 (in other words it doesn't have a natural identifier). 
    60  
    61 The following example shows why natural identifiers are more efficient. 
    62  
    63 Consider three classes Permission, Role and RolePermission. Roles having many permissions and vice versa (so their  
    64 relation is many-to-many). Now lets also assume that each role and permission are naturally identified by their names. 
    65  
    66 Now adding autoincremented primary keys to these classes would be simply stupid. It would require more data and it would  
    67 make the queries more inefficient. For example fetching all permissions for role 'Admin' would be done as follows  
    68 (when using autoinc pks): 
    69  
    70 <code type="sql"> 
    71 SELECT p.*  
    72     FROM Permission p 
    73         LEFT JOIN RolePermission rp ON rp.permission_id = p.id 
    74         LEFT JOIN Role r ON rp.role_id = r.id 
    75     WHERE r.name = 'Admin' 
    76 </code> 
    77  
    78 Now remember sql JOINS are always expensive and here we are using two of those. When using natural identifiers the query  
    79 would look like: 
    80  
    81 <code type="sql"> 
    82 SELECT p.* 
    83     FROM Permission p 
    84         LEFT JOIN RolePermission rp ON rp.permission_name = p.name 
    85     WHERE rp.role_name = 'Admin' 
    86 </code> 
    87  
    88 Thats -1 JOIN !  
    89  
    9057+++ Composite 
    9158 
    92 Composite primary key can be used efficiently in association tables (tables that connect two components together). It is  
    93 not recommended to use composite primary keys in anywhere else as Doctrine does not support mapping relations on multiple  
    94 columns. 
    95  
    96 Due to this fact your doctrine-based system will scale better if it has autoincremented primary key even for association  
    97 tables. 
     59A composite primary key is often used in association tables for example (tables that connect two components together). It is  
     60currently not recommended to use composite primary keys in anywhere else as Doctrine does not support mapping relations on multiple  
     61columns. This will be supported in a future version. 
    9862 
    9963<code type="php">