public function merge(array $metadata): array
	{
		$tables = [];
		foreach ($metadata as $entity) {
			$tables[$entity->getTableName()][] = $entity;
		}

		$merged = [];
		foreach ($tables as $table => $metadata) {

			if (count($metadata) === 1) {
				$merged[] = array_shift($metadata);
				continue;
			}

			$primary = $this->resolvePrimaryMetadata($metadata);
			foreach ($metadata as $secondary) {
				$primary = $this->mergeMetadata($primary, $secondary);
			}

			$primary->fieldMappings = $this->mappingCleanup($primary->fieldMappings);
			$primary->associationMappings = $this->mappingCleanup($primary->associationMappings);
			$merged[] = $primary;
		}

		return $merged;
	}