[FLOW3-general] Relation to value object and general question regarding value objects
Kevin Ulrich Moschallski
km at 3digit.de
Wed Sep 7 21:38:18 CEST 2011
Hi again,
i just wanted to ask what the added paragraph in the documentation means:
"Declares a class as a Value Object, allowing the persistence framework
to reuse an existing object if one exists. Doctrine 2 does not (yet)
support value objects, thus we handle this like an entity for the time
being."
AFAIK this was added by Karsten, as far as i read on the core-v5 list.
Does this mean that valueobjects are handled like entities or does that
mean that the @entity shouldn't be uses at the moment?
For my second question i asked i now bought the DDD book from Eric
Evans, hopefully this will answer my question :), but maybe somebody
gives me a jump start.
Greetings,
Kevin
On 2011-08-23 20:48:53 +0000, Kevin Ulrich Moschallski said:
> Hi list,
>
> i just created a small FLOW3 project. In this project i have an object
> called GeoLocation which has the properties longitude and latitude. I
> wanted this object to be an value object so i added the @valueobject
> notation and wrote the constructor and the getters:
>
> /**
> * A Geo location
> *
> * @scope prototype
> * @valueobject
> */
> class GeoLocation {
> /**
> * @var float
> */
> protected $longitude;
>
> /**
> * @var float
> */
> protected $latitude;
>
> /**
> * Constructs this location
> *
> */
> public function __construct($longitude, $latitude) {
> if (!is_float($longitude)) {
> throw new \InvalidArgumentException('A float value for longitude
> must be passed to this constructor.', 1314040680);
> }
> $this->longitude = $longitude;
> if (!is_float($latitude)) {
> throw new \InvalidArgumentException('A float value for latitude must
> be passed to this constructor.', 1314040681);
> }
> $this->latitude = $latitude;
> }
>
> /**
> * Returns longitude
> *
> * @return float
> */
> public function getLongitude() {
> return $this->longitude;
> }
>
> /**
> * Returns latitude
> *
> * @return float
> */
> public function getLatitude() {
> return $this->latitude;
> }
>
> }
>
> ----
>
> In a second object (address) i added a geolocation property:
>
> /**
> * The geoLocation
> *
> * @var \ThreeDigit\PunchMe\Domain\Model\GeoLocation
> * @ManyToOne
> */
> protected $geoLocation;
>
> When i run typo3.flow3:doctrine:create i get an error about the missing
> id property for the relation.
>
> Now i read on the doctrine documentation, that value objects are only
> supported if they're an instance of DateTime.
>
> So my two questions are:
>
> - Is there a way to get a relation to an value object in FLOW3, i read
> something about serialize the object?
> - And more general, is the decission to setup my GeoLocation object as
> value object i good one, or should it be a entity?
>
> I'm looking forward to hear your replies to learn more about value objects.
>
> Regards,
> Kevin
More information about the FLOW3-general
mailing list