Namespaces for ORM Models and Data Migrations

Two new updates have just been released. The first one is using namespaces for ORM Model table names. Basically it means that \App\Model\Forest\Fairy class would now by default use the forest_fairies table and that relationships with that table would use the forest_fairy_id foreign key. This will lead to a much more obvious connection between tables and their models.

For example it’s now much easier to set up thing like categories for posts and forums by having posts_categories and forum_categories tables and Posts\Category and Forum\Category classes.

The second addition is the support for data migrations in the Migrations Module. Basically a migration might look like this:

<?php
return array(
	'fairies' => array(
	
		'_data' => array(
			'up' => array(
				'insert' => array(
					array('fairy_name' => 'Tinkerbell'),
					array('fairy_name' => 'Trixie')
				),
			),

			'down' => array(
				'delete' => array(
				
					//Same syntax as in where() Query method
					array('fairy_name', 'Tinkerbell'),
					array('fairy_name', 'Trixie')
				)
			
			)
		)
	);

Row updates are also supported, check out the updated Migration Module Tutorial for a more detailed explanation.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>