10.04.2018 Views

Doctrine_manual-1-2-en

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 19: Data Fixtures 290<br />

# ...<br />

Tag:<br />

tutorial:<br />

name: tutorial<br />

Resources: [Resource_1, Resource_2]<br />

doctrine:<br />

name: doctrine<br />

Resources: [Resource_1]<br />

help:<br />

name: help<br />

Resources: [Resource_1, Resource_2]<br />

cheat:<br />

name: cheat<br />

Resources: [Resource_1]<br />

Listing<br />

19-12<br />

Fixtures For Nested Sets<br />

Writing a fixtures file for a nested set tree is slightly differ<strong>en</strong>t from writing regular fixtures<br />

files. The structure of the tree is defined like the following:<br />

---<br />

# fixtures/data.yml<br />

# ...<br />

Category:<br />

Category_1:<br />

name: Categories # the root node<br />

childr<strong>en</strong>:<br />

Category_2:<br />

name: Category 1<br />

Category_3:<br />

name: Category 2<br />

childr<strong>en</strong>:<br />

Category_4:<br />

name: Subcategory of Category 2<br />

Wh<strong>en</strong> writing data fixtures for the NestedSet you must either specify at least a childr<strong>en</strong><br />

elem<strong>en</strong>t of the first data block or specify NestedSet: true under the model which is a<br />

NestedSet in order for the data fixtures to be imported using the NestedSet api.<br />

Listing<br />

19-13<br />

---<br />

# fixtures/data.yml<br />

# ...<br />

Category:<br />

NestedSet: true<br />

Category_1:<br />

name: Categories<br />

# ...<br />

Or simply specifying the childr<strong>en</strong> keyword will make the data fixtures importing using the<br />

NestedSet api.<br />

----------------- Brought to you by

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!