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 235<br />

name: string(30)<br />

username: string(20)<br />

password: string(16)<br />

created: integer(11)<br />

User:<br />

inheritance:<br />

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

type: concrete<br />

Group:<br />

tableName: groups<br />

inheritance:<br />

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

type: concrete<br />

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

// test.php<br />

Listing<br />

15-15<br />

// ...<br />

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

'Group'));<br />

echo $sql[0] . "\n";<br />

echo $sql[1] . "\n";<br />

echo $sql[2] . "\n";<br />

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

CREATE TABLE user (id BIGINT AUTO_INCREMENT,<br />

name VARCHAR(30),<br />

username VARCHAR(20),<br />

password VARCHAR(16),<br />

created BIGINT,<br />

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

CREATE TABLE groups (id BIGINT AUTO_INCREMENT,<br />

name VARCHAR(30),<br />

username VARCHAR(20),<br />

password VARCHAR(16),<br />

created BIGINT,<br />

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

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

name VARCHAR(30),<br />

username VARCHAR(20),<br />

password VARCHAR(16),<br />

created BIGINT,<br />

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

Listing<br />

15-16<br />

Column Aggregation<br />

In the following example we have one database table called <strong>en</strong>tity. Users and groups are<br />

both <strong>en</strong>tities and they share the same database table.<br />

The <strong>en</strong>tity table has a column called type which tells whether an <strong>en</strong>tity is a group or a<br />

user. Th<strong>en</strong> we decide that users are type 1 and groups type 2.<br />

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

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

Saved successfully!

Ooh no, something went wrong!