[FLOW3-general] Relation to value object and general question regarding value objects
Kevin Ulrich Moschallski
km at 3digit.de
Tue Aug 23 22:48:53 CEST 2011
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