asgard/orm

v0.3.1 2016-05-13 11:31 UTC

This package is not auto-updated.

Last update: 2024-11-09 16:06:41 UTC


README

#ORM

Build Status

The ORM package gives you the possibility to store, fetch, search entities and define their relations to each other. It works with the Asgard Entity package.

##Installation If you are working on an Asgard project you don't need to install this library as it is already part of the standard libraries.

composer require asgard/orm 0.*

##Entity Relations

To define relations between entities, please read ORM Relations.

<?php
namespace Blog\Entities\Post;

class Post extends \Asgard\Entity\Entity {
	public static function definition(\Asgard\Entity\Definition $definition) {
		$definition->properties = [
			'title',
			'content',
			'tags' => [
				'type' => 'entity',
				'entity' => 'Blog\Entities\Tag',
				'many'    => true
			],
		];

		$definition->behaviors = [
			new \Asgard\Orm\ORMBehavior
		];
	}
}

##Persistence

To persist and fetch entities, there are two options:

Data Mapper

$dataMapper->save($entity);

ORMBehavior (ActiveRecord pattern)

$entity->save();

##ORM

The ORM class helps you construct queries to manipulate your stored entities. See the documentation.

$entities = $orm->where('position > ?', 5)->orderBy('title ASC')->get();

##Commands

List of commands that come with the ORM package.

###Contributing

Please submit all issues and pull requests to the asgardphp/asgard repository.

License

The Asgard framework is open-sourced software licensed under the MIT license