Notifications
 

How To Write Fixtures Files Manually?

Category Intactix | Asked By Sonal Gupta | Asked On Jun 1, 2014 | 1 Answers
 
Answer using your Joblagao account
 
Close

Leave your answer

 
or answer with facebook account
 
Anant Srivastava answered| Jun 2, 2014

You can write your fixtures files manually and load them in to your applications. Below is a sample data.yml fixtures file. You can also split your data fixtures file up in to multiple files. Doctrine will read all fixtures files and parse them, then load all data.

 

For the next several examples we will use the following models:

 

// models/Resouce.php

class Resource extends Doctrine_Record

{

    public function setTableDefinition()

    {

        $this->hasColumn('name', 'string', 255);

        $this->hasColumn('resource_type_id', 'integer');

    }

 

    public function setUp()

    {

        $this->hasOne('ResourceType as Type', array(

                'local' => 'resource_type_id',

                'foreign' => 'id'

            )

        );

 

        $this->hasMany('Tag as Tags', array(

                'local' => 'resource_id',

                'foreign' => 'tag_id',

                'refClass' => 'ResourceTag'

            )

        );

    }

}

 

// models/ResourceType.php

class ResourceType extends Doctrine_Record

{

    public function setTableDefinition()

    {

        $this->hasColumn('name', 'string', 255);

    }

 

    public function setUp()

    {

        $this->hasMany('Resource as Resouces', array(

                'local' => 'id',

                'foreign' => 'resource_type_id'

            )

        );

    }

}

 

// models/Tag.php

class Tag extends Doctrine_Record

{

    public function setTableDefinition()

    {

        $this->hasColumn('name', 'string', 255);

    }

 

    public function setUp()

    {

        $this->hasMany('Resource as Resources', array(

                'local' => 'tag_id',

                'foreign' => 'resource_id',

                'refClass' => 'ResourceTag'

            )

        );

    }

}

 

// models/ResourceTag.php

class ResourceTag extends Doctrine_Record

{

    public function setTableDefinition()

    {

        $this->hasColumn('resource_id', 'integer');

        $this->hasColumn('tag_id', 'integer');

    }

}

 

// models/Category.php

class BaseCategory extends Doctrine_Record

{

    public function setTableDefinition()

    {

        $this->hasColumn('name', 'string', 255, array(

                'type' => 'string', 'length' => '255'

            )

        );

    }

 

    public function setUp()

    {

        $this->actAs('NestedSet');

    }

}

 

class BaseArticle extends Doctrine_Record

{

    public function setTableDefinition()

    {

        $this->hasColumn('title', 'string', 255, array(

                'type' => 'string', 'length' => '255'

            )

        );

 

        $this->hasColumn('body', 'clob', null, array(

                'type' => 'clob'

            )

        );

    }

 

    public function setUp()

    {

        $this->actAs('I18n', array('fields' => array('title', 'body')));

    }

}