[TYPO3-mvc] @dontpersist

Franz Koch typo3.RemoveForMessage at elements-net.de
Wed Mar 23 11:52:27 CET 2011


Hey,

> what about a situation like this: If I don't want to persist the
> probably unexact result of the location service, I have to recalculate
> the location multiple times during runtime. There is no possibility to
> set the properties just for the runtime
>
> public function getLocation(){
> if(empty($this->lat) || empty($this->lon)){
> try{
> $lat = $this->locationService->getLat($this->address);
> $lon = $this->locationService->getLon($this->address);
>
> // this is not possible without persisting lat and lon
> // $this->lat = $lat;
> // $this->lon = $lon;
>
> return array($lat,$lon);
> }
> catch(Exception $e){
> // do something here
> }
> }
> return array($this->lat,$this->lon);
> }

sorry, but this sounds like a bad concept to me. If the result of the 
locationService might not be what you expect and should not be saved, 
who does decide if it's correct or not? I suppose some controller. So 
why doesn't the controller call the locationService and pass the address 
of your model, perform some checks on the returned lat/long and only 
then set them in the model in order to be persisted?
Another thing you can do is to set your lat/long properties to "private" 
- but in this case they might not be filled with the db-values (haven't 
tested it) - they at least won't be persisted.

You could also use some temporary/private properties that hold your 
temporary lat/long values - like a $location property.


private $location;

public function getLocation() {
   if ($this->location === NULL) {
     ...
     $this->location = array($lat, $long);
   }
   return $this->location;
}


> Cloning doesn't help either, I would have to loop through all models,
> and if they don't have the properties lat and lon set, I have to replace
> them with a clone? That's not what we expect from a frameworks...

so you like to fill the lat/lon properties from within the FE correctly, 
but don't want to persist the calculated values? Why would you wan't 
that? This way you always have to calculate the coordinates over and 
over again.

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list