A
A
Andrey2020-12-19 11:17:54
symfony
Andrey, 2020-12-19 11:17:54

Error when adding a new database connection. Where to fix namespace?

Added another connection to the database, but the error " The class 'App\Entity\MealSQL\Data' was not found in the chain configured namespaces App\Entity\MealSQL> " appears.

Doctrine.yaml

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                url: '%env(resolve:DATABASE_URL)%'
            mssql:
                # configure these for your database server
                url: '%env(DATABASE_MSSQL_URL)%'
                driver: 'php_pdo_sqlsrv_74_ts_x64'
                charset: utf8mb4
            mealSql:
                url: '%env(resolve:DATABASE_MEAL_MYSQL_URL)%'
    orm:
        auto_generate_proxy_classes: true
        default_entity_manager: default
        entity_managers:
            default:
                connection: default
                mappings:
                    App:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/MySql'
                        prefix: 'App\Entity\MySql'
                        alias: App
            mssql:
                connection: mssql
                mappings:
                    Mssql:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/NewElevatorMsSQL'
                        prefix: 'App\Entity\NewElevatorMsSQL'
                        alias: NewElevatorMsSQL
            mealSql:
                connection: mealSql
                mappings:
                    MealSQL:
                        is_bundle: false
                        type: annotation
                        dir: '%kernel.project_dir%/src/Entity/MealSQL'
                        prefix: 'App\Entity\MealSQL>'
                        alias: MealSQL

The namespace App\Entity\MealSQL is specified in Data.php . In controller:
use App\Entity\MealSQL\Data;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class MealController extends AbstractController
{
    /**
     * @Route("/meal", name="meal")
     */
    public function index()
    {
        $em = $this->getDoctrine()->getManager('mealSql')->getRepository(Data::class);
        $model = $em->find(21);

        return $this->json([
            'data' => $model
        ]);
    }
}

There is a connection to this database, since the entity was created via doctrine:mapping:import "App\Entity\MealSQL" annotation --path=src/Entity/MealSQL --em=mealSql

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sl0, 2020-12-19
@DronTat

  1. "The class 'App\Entity\MealSQL\Data' was not found in the chain configured namespaces App\Entity\MealSQL > ".
  2. prefix: 'App\Entity\MealSQL > '
  3. Data.php has namespace App\Entity\MealSQL(?)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question