Browse Source

Add README and composer.json for the ORM package.

Add docs and a composer.json so we can have a subsplit of the ORM
package.
Mark Story 11 years ago
parent
commit
a7e9a177b5
3 changed files with 145 additions and 5 deletions
  1. 6 5
      composer.json
  2. 112 0
      src/ORM/README.md
  3. 27 0
      src/ORM/composer.json

+ 6 - 5
composer.json

@@ -52,15 +52,16 @@
 		}
 	},
 	"replace": {
+		"cakephp/cache": "self.version",
 		"cakephp/collection": "self.version",
-		"cakephp/event": "self.version",
-		"cakephp/validation": "self.version",
-		"cakephp/utility": "self.version",
 		"cakephp/core": "self.version",
 		"cakephp/datasource": "self.version",
 		"cakephp/database": "self.version",
-		"cakephp/cache": "self.version",
+		"cakephp/event": "self.version",
+		"cakephp/i18n": "self.version",
 		"cakephp/log": "self.version",
-		"cakephp/i18n": "self.version"
+		"cakephp/orm": "self.version",
+		"cakephp/utility": "self.version",
+		"cakephp/validation": "self.version"
 	}
 }

+ 112 - 0
src/ORM/README.md

@@ -0,0 +1,112 @@
+# CakePHP ORM
+
+The CakePHP ORM provides a powerful and flexible way to work with relational
+databases. Using a datamapper pattern the ORM allows you to manipulate data as
+entities allowing you to create expressive domain layers in your applications.
+
+## Connecting to the Database
+
+The CakePHP ORM is compatible with:
+
+* MySQL 5.1+
+* Postgres 8+
+* SQLite3
+* SQLServer 2008+
+
+The first thing you need to do when using this library is register a connection
+object.  Before performing any operations with the connection, you need to
+specify a driver to use:
+
+```php
+use Cake\Datasource\ConnectionManager;
+
+ConnectionManager::create('default', [
+	'driver' => 'Cake\Database\Driver\Mysql',
+	'database' => 'test',
+	'login' => 'root',
+	'password' => 'secret'
+]);
+```
+
+Once a 'default' connection is registered, it will be used by all the Table
+mappers if no explicit connection is defined.
+
+## Creating Associations
+
+In your table classes you can define the relations between your tables. CakePHP
+supports 4 association types out of the box:
+
+* belongsTo - E.g. Many articles belong to a user.
+* hasOne - E.g. A user has one profile
+* hasMany - E.g. A user has many articles
+* belongsToMany - E.g. An article belongsToMany tags.
+
+You define associations in your table's `initialize()` method. See the
+[documentation](http://book.cakephp.org/3.0/en/orm/associations.html) for
+complete examples.
+
+## Reading Data
+
+Once you've defined some table classes you can read existing data in your tables:
+
+```php
+use Cake\ORM\TableRegistry;
+
+$articles = TableRegistry::get('Articles');
+foreach ($articles->find() as $article) {
+	echo $article->title;
+}
+```
+
+You can use the [query builder](http://book.cakephp.org/3.0/en/orm/query-builder.html) to create
+complex queries, and a [variety of methods](http://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html)
+to access your data.
+
+## Saving Data
+
+Table objects provide ways to convert request data into entities, and then persist
+those entities to the database:
+
+```php
+use Cake\ORM\TableRegistry;
+
+$data = [
+	'title' => 'My first article',
+	'body' => 'It is a great article',
+	'user_id' => 1,
+	'tags' => [
+		'_ids' => [1, 2, 3]
+	],
+	'comments' => [
+		['comment' => 'Good job'],
+		['comment' => 'Awesome work'],
+	]
+];
+
+$articles = TableRegistry::get('Articles');
+$article = $articles->newEnitity($data, [
+	'associated' => ['Tags', 'Comments']
+]);
+$articles->save($article, [
+	'associated' => ['Tags', 'Comments']
+])
+```
+
+The above shows how you can easily marshal and save an entity and its
+associations in a simple & powerful way. Consult the [ORM documentation](http://book.cakephp.org/3.0/en/orm/saving-data.html)
+for more in-depth examples.
+
+## Deleting Data
+
+Once you have a reference to an entity, you can use it to delete data:
+
+```php
+$articles = TableRegistry::get('Articles');
+$article = $articles->get(2);
+$articles->delete($article);
+```
+
+## Additional Documentation
+
+Consult [the CakePHP documentation](http://book.cakephp.org/3.0/en/orm.html)
+for more in-depth documentation.

+ 27 - 0
src/ORM/composer.json

@@ -0,0 +1,27 @@
+{
+	"name": "cakephp/orm",
+	"description": "CakePHP ORM - Provides a flexible and powerful ORM implementing a data-mapper pattern.",
+	"license": "MIT",
+	"authors": [
+		{
+		"name": "CakePHP Community",
+		"homepage": "http://cakephp.org"
+	}
+	],
+	"autoload": {
+		"psr-4": {
+			"Cake\\ORM\\": "."
+		}
+	},
+	"require": {
+		"cakephp/collection": "dev-master",
+		"cakephp/core": "dev-master",
+		"cakephp/datasource": "dev-master",
+		"cakephp/database": "dev-master",
+		"cakephp/event": "dev-master",
+		"cakephp/i18n": "dev-master",
+		"cakephp/utility": "dev-master",
+		"cakephp/validation": "dev-master"
+	},
+	"minimum-stability": "beta"
+}