Changeset 11597
- Timestamp:
- 09/16/08 17:27:33 (2 months ago)
- Files:
-
- doc/branches/1.2/doctrine_book/en/01-Getting-Started.txt (modified) (3 diffs)
- doc/branches/1.2/doctrine_book/en/02-Connections.txt (modified) (7 diffs)
- doc/branches/1.2/doctrine_book/en/03-Configuration.txt (modified) (3 diffs)
- doc/branches/1.2/doctrine_book/en/04-Data-Fixtures.txt (deleted)
- doc/branches/1.2/doctrine_book/en/04-Schema Files.txt (added)
- doc/branches/1.2/doctrine_book/en/05-Data-Fixtures.txt (added)
- doc/branches/1.2/doctrine_book/en/05-Migrations.txt (deleted)
- doc/branches/1.2/doctrine_book/en/06-Admin-Generator-And-Crud.txt (deleted)
- doc/branches/1.2/doctrine_book/en/06-Migrations.txt (added)
- doc/branches/1.2/doctrine_book/en/07-Admin-Generator-And-Crud.txt (added)
- doc/branches/1.2/doctrine_book/en/07-Forms.txt (deleted)
- doc/branches/1.2/doctrine_book/en/08-Forms.txt (added)
- doc/branches/1.2/doctrine_book/en/09-Routing.txt (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
doc/branches/1.2/doctrine_book/en/01-Getting-Started.txt
r11589 r11597 1 # Getting Started 1 Chapter 1 - Getting Started 2 =========================== 2 3 3 4 In order to begin using Doctrine you must first enable it in your application with the following command. It will automatically make some configuration changes and create directories that Doctrine require. … … 12 13 13 14 ## Available Tasks 15 16 Below is the complete list of tasks available with the sfDoctrinePlugin. It offers all the same functionality as propel plus much more. 14 17 15 18 $ ./symfony list doctrine … … 55 58 >> doctrine Generate YAML schema successfully from database 56 59 57 Now have a look in config/doctrine/schema.ymland you will see the yaml for the database. In this example we have a user table.60 Now have a look in `config/doctrine/schema.yml` and you will see the yaml for the database. In this example we have a user table. 58 61 59 62 CREATE TABLE user (id BIGINT AUTO_INCREMENT, username VARCHAR(255), password VARCHAR(255), PRIMARY KEY(id)) ENGINE = INNODB; 60 63 61 The above mysql table would generate a yaml schema like the following .64 The above mysql table would generate a yaml schema like the following in `config/doctrine/schema.yml` 62 65 63 66 --- doc/branches/1.2/doctrine_book/en/02-Connections.txt
r11589 r11597 1 # Connections 1 Chapter 2 - Connections 2 ======================= 2 3 3 In this chapter we'll explain some things about Doctrine connections . How to configure them, how to use multiple of them and bind models to connections, how to create and drop your databases and other connection related activities.4 In this chapter we'll explain some things about Doctrine connections, how to configure them, how to use multiple of them and bind models to connections, how to create and drop your databases and other connection related activities. 4 5 5 The default databases.yml should look something like this.6 The default `config/databases.yml` should look like the following. The only difference here is that it is sfDoctrineDatabase instead of sfPropelDatabase and the connection name is doctrine instead of propel. 6 7 7 8 all: … … 25 26 * SQLite — SQLite Functions (PDO_SQLITE) 26 27 28 ## DSN 27 29 28 ## DSN 30 Doctrine offers two ways of specifying your DSN information. You can use the portable Doctrine style DSN or use the native PDO style DSN. 29 31 30 32 ### Doctrine Style … … 50 52 password: password 51 53 54 >**TIP** 55 >Using the PDO style syntax offers more flexibility and ability to specify non standard information about your connection to PDO. For example, when specifying non standard unix_socket paths or ports to use when connecting, specifying it in PDO syntax is more flexible. 56 52 57 ## Multiple Connections 53 58 54 Doctrine offers the ability to have multiple connection instances and bind models to connections so all model operations are executed on a specific connection. Below is an example config/databases.ymlwith multiple databases.59 Doctrine offers the ability to have multiple connections. You can easily bind models to connections so that queries are executed on the appropriate dbms. Below is an example `config/databases.yml` with multiple databases. 55 60 56 61 all: … … 64 69 dsn: mysql://root@localhost/client 65 70 66 Now say we have a User model which you want to bind to the master database. You can simply do this directly in the definition of the model like below. Place the following YAML code in config/doctrine/schema.yml71 Now say we have a User model which you want to bind to the master database. You can simply do this directly in the definition of the model like below. Place the following YAML code in `config/doctrine/schema.yml` 67 72 68 73 Client: … … 73 78 password: string(255) 74 79 75 Now each Client can have Stores but they are s tored in a separate database from the Users.80 Now each Client can have Stores but they are saved in a separate database from the Users. 76 81 77 82 Store: … … 88 93 89 94 >**Note** 90 >Because the tables are in separate databases the data can only be lazily loaded. Doctrine does not currently support generating sql for joining tables across databases. Also notice the export attributes being set to tables so Doctrine does not try and export any foreign keys to the dbms.95 >Because the tables are in separate databases the data can only be lazily loaded. Doctrine does not currently support generating sql for joining tables across databases. Also, notice the export attribute being set to tables. This tells Doctrine to only export the create table statement and not any foreign keys. 91 96 92 97 ## Build Everything 93 98 94 Now that we have our connections and schema defined we can build everything with the following command. 99 Now that we have our connections and schema defined we can build everything with the following command. This command will drop your database if it already exists, re-create it, build your models from `config/doctrine/*.yml`, create the tables in your databases and load your data fixtures from `data/fixtures/*.yml`. 95 100 96 101 ./symfony doctrine-build-all-reload frontend … … 107 112 >**Note** 108 113 >You can take a look at the models which were generated from your YAML schema files in lib/model/doctrine and lib/model/doctrine/generated. The files in the generated folder are re-written each time you build your models whereas the ones below the generated directory are not. You may customize your models by editing the classes in lib/model/doctrine. 114 115 Here is what the `lib/model/doctrine/generated/BaseClient.class.php` should look like. 116 117 [php] 118 /** 119 * This class has been auto-generated by the Doctrine ORM Framework 120 */ 121 abstract class BaseClient extends sfDoctrineRecord 122 { 123 public function setTableDefinition() 124 { 125 $this->setTableName('client'); 126 $this->hasColumn('name', 'string', 255, array('type' => 'string', 'length' => '255')); 127 $this->hasColumn('username', 'string', 255, array('type' => 'string', 'length' => '255')); 128 $this->hasColumn('password', 'string', 255, array('type' => 'string', 'length' => '255')); 129 } 130 131 public function setUp() 132 { 133 $this->hasMany('Store as Stores', array('local' => 'id', 134 'foreign' => 'client_id')); 135 } 136 } 137 138 >**TIP** 139 >It is common practice to run the `./symfony doctrine:build-all-reload-test` command when developing. This will rebuild your entire environment and run the full test suite. This is a good command to run before committing new code to ensure no new regressions have occurred. doc/branches/1.2/doctrine_book/en/03-Configuration.txt
r11589 r11597 1 # Configuration 1 Chapter 3 - Configuration 2 ========================= 2 3 3 Doctrine controls most configuration from the project/apps/frontend/config/doctrine.yml which should have beencopied for you with the `$ ./symfony doctrine:enable frontend` command. Below is the sample configuration that comes bundled with Doctrine.4 Doctrine controls most configuration from the `project/apps/frontend/config/doctrine.yml` which was copied for you with the `$ ./symfony doctrine:enable frontend` command. Below is the sample configuration that comes bundled with Doctrine. 4 5 5 6 all: … … 34 35 ## Attributes 35 36 36 Doctrine controls features and settings with attributes. The attributes can be defined at different levels of a hierarchy. Some attributes can be specified at all levels and others cannot. This chapterexplains how you can specify attributes at each level. Attributes can be specified globally, on each connection, or on each individual model.37 Doctrine controls features and settings with attributes. The attributes can be defined at different levels of a hierarchy. Some attributes can be specified at all levels and others cannot. Below explains how you can specify attributes at each level. Attributes can be specified globally, on each connection, or on each individual model. 37 38 38 39 ### Global Attributes 39 40 40 You can specify global attributes by editing project/apps/frontend/config/doctrine.yml.41 You can specify global attributes by editing `project/apps/frontend/config/doctrine.yml`. 41 42 42 43 all: … … 46 47 ### Connection Attributes 47 48 48 You can specify connection attributes the same way you do global ones in project/apps/frontend/config/doctrine.ymlwith the following YAML.49 You can specify connection attributes the same way you do global ones in `project/apps/frontend/config/doctrine.yml` with the following YAML. 49 50 50 51 all: