You can write your fixtures files manually and load them in to your applications. Below is a sample data.yml fixtures file
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.
Please see the [doc schema-files :index :name] for the sample models/schema for these example fixtures.
<code type="yml">
---
Email:
Email_1:
address: jwage@mac.com
Group:
Group_1:
name: Drama Actors
Adult:
Adult_1:
name: Parent 1
Contact: Contact_1
Car:
Car_1:
name: Chevorlet Trailblazer
Car_2:
name: Chevorlet Blazer
Car_3:
name: Buick
Child:
Child_1:
name: Child 1
Adult: Adult_1
Contact:
Contact_1:
name: Jonathan H. Wage
Contact_3:
name: Daniel Adams
Contact_4:
name: Robert Adams
Dog:
Dog_1:
name: Sam
User: User_1
Dog_2:
name: Dixie
User: User_2
Dog_3:
name: Chief
User: User_3
SelfReference:
SelfReference_1:
User1: User_1
User2: User_2
name: Self Reference 1
SelfReference1: SelfReference_2
SelfReference2: SelfReference_3
SelfReference_2:
User1: User_2
User2: User_1
name: Self Reference 2
SelfReference1: SelfReference_1
SelfReference2: SelfReference_1
SelfReference_3:
User1: User_2
User2: User_1
name: Self Reference 3
SelfReference1: SelfReference_3
SelfReference2: SelfReference_3
User:
User_1:
Phonenumber: Phonenumber_1
name: Jonathan H. Wage
loginname: jwage
Email: Email_1
Groupuser:
Groupuser_1:
Group: Group_1
username: jwage
hair_color: light brown
Contact: Contact_1
User_2:
username: dadams
hair_color: dark brown
Contact: Contact_3
User_3:
username: radams
hair_color: light brown
Contact: Contact_4
UserCar:
UserCar_1:
User: User_1
Phonenumber:
Phonenumber_1:
phonenumber: 555-555-5555
Group: Group_1
Car: Car_1
UserCar_2:
User: User_2
Car: Car_2
UserCar_3:
User: User_3
Car: Car_3
</code>
Here is how you would write code to load the data from that data.yml file
The purpose of schema files is to allow you to manage your model definitions directly from a yaml file rather then editing php code. The yaml schema file is parsed and used to generate all your model definitions/classes.
Schema files support all the normal things you would write with manual php code. Component to connection binding, relationships, attributes, templates/behaviors, indexes, etc.
++ Example Schema File
'tableName' and 'className' are optional. If not specified they will be set by the key of the yaml block
Below is an example schema file for generating a set of models.
You will notice in this schema file it is not always necessary to specify the local and foreign parameters on a relationship. If the foreign columns follow the naming patterns, Doctrine can successfully guess each of them.
schema.yml
<code type="yml">
---
User:
Group:
# bind this model to connection1
connection: connection1
columns:
id:
notnull: true
...
...
@@ -18,16 +24,26 @@ User:
type: integer
length: 4
name: id
username:
name:
type: string
length: 255
relations:
Groups:
class: Group
Users:
class: User
refClass: UserGroup
local: user_id
foreign: group_id
type: many
# set attributes on the model
attributes:
export: tables
# you can set templates on your schema with the following syntax
# if you do not require any options to be set for the template
# actAs and templates are the same, actAs serves as a convenience method for the Templates/Plugins
This is the directory structure that would be generated at /path/to/generate/models
This is the directory structure that would be generated at /path/to/generate/models. The base classes contain the actual definitions for the model, and the top level models extend the base and they are only written the first time so you are able to modify them without your additions being overwritten.
<code>
- Adult.class.php
- Car.class.php
- Child.class.php
- Contact.class.php
- Dog.class.php
- Entity.class.php
- Group.class.php
- SelfReference.class.php
- User.class.php
- UserCar.class.php
- UserGroup.class.php
- generated
- BaseAdult.class.php
- BaseCar.class.php
- BaseChild.class.php
- BaseContact.class.php
- BaseDog.class.php
- BaseEntity.class.php
- BaseGroup.class.php
- BaseSelfReference.class.php
- BaseUser.class.php
- BaseUserCar.class.php
- BaseUserGroup.class.php
</code>
And finally here is the code for each of the generated models
<code type="php">
// Group.class.php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class Group extends BaseGroup
{
}
// User.class.php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class User extends BaseUser
{
}
// UserGroup.class.php
/**
* This class has been auto-generated by the Doctrine ORM Framework
*/
class UserGroup extends BaseUserGroup
{
}
// BaseGroup.class.php
/**
* This class has been auto-generated by the Doctrine ORM Framework