Ho bisogno di spostare alcuni campi immutabili in una classe separata, ma in realtà non voglio usare "join", perché ho bisogno di tutti i dati insieme ogni volta.Doctrine2 sposta i campi immutabili nella classe separata
È possibile avere alcuni attributi di entità come classi associate alla stessa tabella?
Qualcosa di simile:
/**
* @ORM\Entity
*/
class User {
/**
* @var int
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
...
/**
* @var Address
* @ORM\... ??
*/
protected $address
}
/**
* @ORM\ValueObject ??
*/
class Address {
/**
* @var string
* @ORM\Column(type="string", name="address_zipcode", length=12)
*/
protected $zipcode;
/**
* @var string
* @ORM\Column(type="string", name="address_country_iso", length=3)
*/
protected $countryIso;
...
}
E la struttura della tabella sarebbe:
CREATE TABLE User (
`id` INT(11) NOT NULL auto_increment,
`address_zipcode` VARCHAR(12) NOT NULL,
`address_country_iso` VARCHAR(3) NOT NULL,
PRIMARY KEY (`id`)
);
Probabilmente [qui] (http://stackoverflow.com/questions/8440879/doctrine-2-value-objects) è possibile trovare la risposta a questa domanda. –
Mille grazie, questo è esattamente quello che sto cercando –