2009-05-21 12:53:40 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\Models\Company;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Description of CompanyPerson
|
|
|
|
*
|
|
|
|
* @author robo
|
2009-05-29 14:23:13 +04:00
|
|
|
* @Entity
|
|
|
|
* @Table(name="company_persons")
|
2009-06-07 21:20:37 +04:00
|
|
|
* @InheritanceType("JOINED")
|
2009-05-29 14:23:13 +04:00
|
|
|
* @DiscriminatorColumn(name="discr", type="string")
|
2009-08-17 21:58:16 +04:00
|
|
|
* @DiscriminatorMap({
|
2012-02-29 06:17:29 +04:00
|
|
|
* "person" = "CompanyPerson",
|
|
|
|
* "manager" = "CompanyManager",
|
|
|
|
* "employee" = "CompanyEmployee"
|
|
|
|
* })
|
|
|
|
*
|
|
|
|
* @NamedNativeQueries({
|
|
|
|
* @NamedNativeQuery(
|
|
|
|
* name = "fetchAllWithResultClass",
|
|
|
|
* resultClass = "__CLASS__",
|
|
|
|
* query = "SELECT id, name, discr FROM company_persons ORDER BY name"
|
|
|
|
* ),
|
|
|
|
* @NamedNativeQuery(
|
|
|
|
* name = "fetchAllWithSqlResultSetMapping",
|
|
|
|
* resultSetMapping= "mappingFetchAll",
|
|
|
|
* query = "SELECT id, name, discr AS discriminator FROM company_persons ORDER BY name"
|
|
|
|
* )
|
|
|
|
* })
|
|
|
|
*
|
|
|
|
* @SqlResultSetMappings({
|
|
|
|
* @SqlResultSetMapping(
|
|
|
|
* name = "mappingFetchAll",
|
|
|
|
* entities= {
|
|
|
|
* @EntityResult(
|
|
|
|
* entityClass = "__CLASS__",
|
|
|
|
* discriminatorColumn = "discriminator",
|
|
|
|
* fields = {
|
|
|
|
* @FieldResult("id"),
|
|
|
|
* @FieldResult("name"),
|
|
|
|
* }
|
|
|
|
* )
|
|
|
|
* }
|
|
|
|
* )
|
|
|
|
* })
|
2009-05-21 12:53:40 +04:00
|
|
|
*/
|
|
|
|
class CompanyPerson
|
|
|
|
{
|
|
|
|
/**
|
2009-05-29 14:23:13 +04:00
|
|
|
* @Id
|
|
|
|
* @Column(type="integer")
|
2010-04-10 02:00:36 +04:00
|
|
|
* @GeneratedValue
|
2009-05-21 12:53:40 +04:00
|
|
|
*/
|
|
|
|
private $id;
|
2012-05-23 09:07:29 +04:00
|
|
|
|
2009-05-21 12:53:40 +04:00
|
|
|
/**
|
2010-04-10 02:00:36 +04:00
|
|
|
* @Column
|
2009-05-21 12:53:40 +04:00
|
|
|
*/
|
|
|
|
private $name;
|
2012-05-23 09:07:29 +04:00
|
|
|
|
2009-05-21 12:53:40 +04:00
|
|
|
/**
|
2012-01-15 14:27:28 +04:00
|
|
|
* @OneToOne(targetEntity="CompanyPerson")
|
2012-05-23 09:07:29 +04:00
|
|
|
* @JoinColumn(name="spouse_id", referencedColumnName="id", onDelete="CASCADE")
|
2009-05-21 12:53:40 +04:00
|
|
|
*/
|
|
|
|
private $spouse;
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2009-06-14 21:34:28 +04:00
|
|
|
/**
|
|
|
|
* @ManyToMany(targetEntity="CompanyPerson")
|
2012-05-23 09:07:29 +04:00
|
|
|
* @JoinTable(
|
|
|
|
* name="company_persons_friends",
|
|
|
|
* joinColumns={
|
|
|
|
* @JoinColumn(name="person_id", referencedColumnName="id", onDelete="CASCADE")
|
|
|
|
* },
|
|
|
|
* inverseJoinColumns={
|
|
|
|
* @JoinColumn(name="friend_id", referencedColumnName="id", onDelete="CASCADE")
|
|
|
|
* }
|
|
|
|
* )
|
2009-06-14 21:34:28 +04:00
|
|
|
*/
|
|
|
|
private $friends;
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2009-08-17 21:58:16 +04:00
|
|
|
public function __construct() {
|
|
|
|
$this->friends = new \Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
}
|
2009-05-21 12:53:40 +04:00
|
|
|
|
|
|
|
public function getId() {
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName() {
|
|
|
|
return $this->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setName($name) {
|
|
|
|
$this->name = $name;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSpouse() {
|
|
|
|
return $this->spouse;
|
|
|
|
}
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2009-06-14 21:34:28 +04:00
|
|
|
public function getFriends() {
|
|
|
|
return $this->friends;
|
|
|
|
}
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2009-06-14 21:34:28 +04:00
|
|
|
public function addFriend(CompanyPerson $friend) {
|
|
|
|
if ( ! $this->friends->contains($friend)) {
|
|
|
|
$this->friends->add($friend);
|
|
|
|
$friend->addFriend($this);
|
|
|
|
}
|
|
|
|
}
|
2009-05-21 12:53:40 +04:00
|
|
|
|
|
|
|
public function setSpouse(CompanyPerson $spouse) {
|
|
|
|
if ($spouse !== $this->spouse) {
|
|
|
|
$this->spouse = $spouse;
|
|
|
|
$this->spouse->setSpouse($this);
|
|
|
|
}
|
|
|
|
}
|
2012-03-10 07:04:46 +04:00
|
|
|
|
|
|
|
public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
|
|
|
|
{
|
|
|
|
|
|
|
|
$metadata->setPrimaryTable(array(
|
|
|
|
'name' => 'company_person',
|
|
|
|
));
|
|
|
|
|
|
|
|
$metadata->addNamedNativeQuery(array (
|
|
|
|
'name' => 'fetchAllWithResultClass',
|
|
|
|
'query' => 'SELECT id, name, discr FROM company_persons ORDER BY name',
|
|
|
|
'resultClass' => 'Doctrine\\Tests\\Models\\Company\\CompanyPerson',
|
|
|
|
));
|
|
|
|
|
|
|
|
$metadata->addNamedNativeQuery(array (
|
|
|
|
'name' => 'fetchAllWithSqlResultSetMapping',
|
|
|
|
'query' => 'SELECT id, name, discr AS discriminator FROM company_persons ORDER BY name',
|
|
|
|
'resultSetMapping' => 'mappingFetchAll',
|
|
|
|
));
|
|
|
|
|
|
|
|
$metadata->addSqlResultSetMapping(array (
|
|
|
|
'name' => 'mappingFetchAll',
|
|
|
|
'columns' => array(),
|
|
|
|
'entities' => array ( array (
|
|
|
|
'fields' => array (
|
|
|
|
array (
|
|
|
|
'name' => 'id',
|
|
|
|
'column' => 'id',
|
|
|
|
),
|
|
|
|
array (
|
|
|
|
'name' => 'name',
|
|
|
|
'column' => 'name',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'entityClass' => 'Doctrine\Tests\Models\Company\CompanyPerson',
|
|
|
|
'discriminatorColumn' => 'discriminator',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
2009-05-21 12:53:40 +04:00
|
|
|
}
|
|
|
|
|