private function checkAndAssignClassName($objects)
    {
        foreach ($objects as $object)
        {
            if ($this->targetClassName === null)
            {
                $this->targetClassName = $object->getClassName();
            }
            if ($this->targetClassName != $object->getClassName())
            {
                throw new \Exception('All objects in a relation must be of the same class.');
            }
        }
    }