What I want to accomplish is the following.

I need to save in database some field which value should be automatically calculated using other values in its Model (or related models). I guess I should do this using one of these model hooks - beforeInsert, beforeModify, afterInsert, afterModify, but how exactly I should do this?
Also, this field should be not changeable, but visible in UI forms/grids.

For example,

```
class Model_Address extends Model_Table{
  public $table='address';
  function init(){
    parent::init();

    $this->hasOne('Territory');
    $this->addField('street');
    $this->addField('house');
    $this->addField('number');
    $this->addField('name')->readonly(true); // this should be calculated on save

    $this->addHook('beforeModify',$this);
  }

  // How to write this to set name=street+house+number+territory.name ???
  function beforeModify($m){
    $ter_name = $m->ref('Territory')->get('name');
    $m['name'] = $m['street'].' '.$m['house'].' '.$m['number'].', '.$ter_name;
    return $m;
  }
}

```

---

Edit:

Will this solution will be correct? It looks that it's working, but I'm not sure yet.

```
class Model_Address extends Model_Table{
  public $table='address';
  function init(){
    parent::init();

    $this->hasOne('Territory');
    $this->addField('street');
    $this->addField('house');
    $this->addField('number');
    $this->addField('name')->readonly(true); // this should be calculated on save

    $this->addHook('beforeSave',$this);
  }

  function beforeSave($m){
    $t=$m->ref('territory_id');
    if($t->loaded()){
      $m=set('name',$m->get('street').' '.$m->get('house').' '.$m->get('number').', '.$t->get('name'));
    }
    return $this;
  }
}

```