public function set($data, $bean) {

		// Add all properties to bean
		foreach ( $this->properties as $property ) {

			$value = false; // We need to clear possible previous $value

			// Define property controller
			$c = new $property['type'];

			// New input for the property
			if (
				isset( $data[ $property['name'] ] )
				|| 
				( isset( $_FILES[ $property['name'] ] ) && $_FILES[ $property['name'] ]['size'] > 0 )
				||
				$property['autovalue'] == true
			) {

				// Check if specific set property type method exists
				if ( method_exists( $c, 'set' ) ) {

					$value = $c->set( $bean, $property, $data[ $property['name'] ] );

				} else {

					$value = $data[ $property['name'] ];

				}

				if ($value) {
					$hasvalue = true;
				} else {
					$hasvalue = false;
				}

			// No new input for the property
			} else {

				// Check if property already has value for required validation
				if ( isset( $property['required'] ) ) {

					if ( method_exists( $c, 'read' ) && $c->read( $bean, $property ) ) {
						$hasvalue = true;
					} else if ( $bean->{ $property['name'] } ) {
						$hasvalue = true;
					} else {
						$hasvalue = false;
					}

				}

			}

			// Check if property is required
			if ( isset( $property['required'] ) ) {
				if ( $property['required'] && !$hasvalue ) {
					throw new \Exception('Validation error. '.$property['description'].' is required.');
				}
			}

			// Results from methods that return boolean values are not stored.
			// Many-to-many relations for example are stored in a seperate table.
			if ( !is_bool($value) ) {

				// Check if property value is unique
				if ( isset( $property['unique'] ) ) {
					$duplicate = \R::findOne( $this->type, $property['name'].' = :val ', [ ':val' => $value ] );
					if ( $duplicate && $duplicate->id != $bean->id ) {
						throw new \Exception('Validation error. '.$property['description'].' should be unique.');
					}
				}

				$bean->{ $property['name'] } = $value;
			}

		}

		$bean->modified = \R::isoDateTime();
		\R::store($bean);

		return $bean;

	}