10.04.2018 Views

Doctrine_manual-1-2-en

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 15: Inheritance 232<br />

Listing<br />

15-5<br />

class Group ext<strong>en</strong>ds Entity<br />

{ }<br />

Here is the same example in YAML format. You can read more about YAML in the YAML<br />

Schema Files (page 195) chapter:<br />

---<br />

# schema.yml<br />

# ...<br />

Entity:<br />

columns:<br />

name: string(30)<br />

username: string(20)<br />

password: string(16)<br />

created_at: timestamp<br />

updated_at: timestamp<br />

User:<br />

inheritance:<br />

ext<strong>en</strong>ds: Entity<br />

type: simple<br />

Group:<br />

inheritance:<br />

ext<strong>en</strong>ds: Entity<br />

type: simple<br />

Lets check the SQL that is g<strong>en</strong>erated by the above models:<br />

Listing<br />

15-6<br />

// test.php<br />

// ...<br />

$sql = <strong>Doctrine</strong>_Core::g<strong>en</strong>erateSqlFromArray(array('Entity', 'User',<br />

'Group'));<br />

echo $sql[0];<br />

The above code would output the following SQL query:<br />

Listing<br />

15-7<br />

CREATE TABLE <strong>en</strong>tity (id BIGINT AUTO_INCREMENT,<br />

username VARCHAR(20),<br />

password VARCHAR(16),<br />

created_at DATETIME,<br />

updated_at DATETIME,<br />

name VARCHAR(30),<br />

PRIMARY KEY(id)) ENGINE = INNODB<br />

Wh<strong>en</strong> using YAML schema files you are able to define columns in the child classes but<br />

wh<strong>en</strong> the YAML is parsed the columns are moved to the par<strong>en</strong>t for you automatically. This<br />

is only a conv<strong>en</strong>i<strong>en</strong>ce to you so that you can organize your columns easier.<br />

Concrete<br />

Concrete inheritance creates separate tables for child classes. However in concrete<br />

inheritance each class g<strong>en</strong>erates a table which contains all columns (including inherited<br />

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

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

Saved successfully!

Ooh no, something went wrong!