public function set($key, $value)
 {
     if ($this->hasProperty($key)) {
         return parent::set($key, $value);
     }
     if (!array_key_exists($key, $this->settings) || $value !== $this->settings[$key]) {
         $this->hasBeenModified = true;
     }
     $this->settings[$key] = $value;
     return $this;
 }
 public function set($key, $value)
 {
     if ($key === 'groups') {
         $this->groups()->set($value);
         return $this;
     } elseif ($key === 'imports') {
         $this->imports()->set($value);
         return $this;
     } elseif ($key === 'arguments') {
         if (is_object($value)) {
             foreach ($value as $arg => $val) {
                 $this->arguments()->set($arg, $val);
             }
         }
         return $this;
     } elseif ($key === 'vars') {
         $value = (array) $value;
         $unset = array();
         foreach ($this->vars() as $k => $f) {
             if (!array_key_exists($k, $value)) {
                 $unset[] = $k;
             }
         }
         foreach ($unset as $k) {
             unset($this->vars()->{$k});
         }
         foreach ($value as $k => $v) {
             $this->vars()->set($k, $v);
         }
         return $this;
     }
     if ($this->propertyIsBoolean($key) && $value !== null) {
         if ($value === 'y' || $value === '1' || $value === true || $value === 1) {
             return parent::set($key, 'y');
         } elseif ($value === 'n' || $value === '0' || $value === false || $value === 0) {
             return parent::set($key, 'n');
         } elseif ($value === '') {
             return parent::set($key, null);
         } else {
             throw new ProgrammingError('Got invalid boolean: %s', var_export($value, 1));
         }
     }
     if ($this->hasRelation($key)) {
         if (!$value) {
             return parent::set($key . '_id', null);
         }
         $class = $this->getRelationClass($key);
         $object = $class::load($value, $this->connection);
         if (in_array($object->object_type, array('object', 'external_object'))) {
             return parent::set($key . '_id', $object->id);
         }
         // TODO: what shall we do if it is a template? Fail?
     }
     return parent::set($key, $value);
 }