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 16: Behaviors 258<br />

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

title VARCHAR(255),<br />

description LONGTEXT,<br />

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

ALTER TABLE job_index ADD FOREIGN KEY (id) REFERENCES job(id) ON UPDATE<br />

CASCADE ON DELETE CASCADE<br />

Notice how the job_index table is automatically created for you and a foreign key<br />

betwe<strong>en</strong> job and job_index was automatically created.<br />

Because the Searchable behavior is such a large topic, we have more information on this<br />

that can be found in the Searching (page 267) chapter.<br />

Geographical<br />

The below is only a demo. The Geographical behavior can be used with any data record for<br />

determining the number of miles or kilometers betwe<strong>en</strong> 2 records.<br />

Listing<br />

16-57<br />

// models/Zipcode.php<br />

class Zipcode ext<strong>en</strong>ds <strong>Doctrine</strong>_Record<br />

{<br />

public function setTableDefinition()<br />

{<br />

$this->hasColumn('zipcode', 'string', 255);<br />

$this->hasColumn('city', 'string', 255);<br />

$this->hasColumn('state', 'string', 2);<br />

$this->hasColumn('county', 'string', 255);<br />

$this->hasColumn('zip_class', 'string', 255);<br />

}<br />

}<br />

public function setUp()<br />

{<br />

$this->actAs('Geographical');<br />

}<br />

Listing<br />

16-58<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 />

Zipcode:<br />

actAs: [Geographical]<br />

columns:<br />

zipcode: string(255)<br />

city: string(255)<br />

state: string(2)<br />

county: string(255)<br />

zip_class: string(255)<br />

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

Listing<br />

16-59<br />

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

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

Saved successfully!

Ooh no, something went wrong!