Developer Blog

  • Blog
  • /
  • Namespaces for ORM Models and Data Migrations
By Dracony on 4 June 2013

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?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.

comments powered by Disqus