Bonjour à tous,
J'ai débuté il y a peu sur Symfony et coince sur un truc qui me parait pourtant simple. Un oeil avisé saura peut-être m'aider 
Je souhaiterais lier une table "ecriture" à une table "budget"
dans écriture, il y a un champ numero_sectionAnalytique et numero_service
dans budget il y a en ID de la table numero_sectionAnalytique, numero_service.
le but final étant de réussir à retourner
1 2 3 4 5 6 7 8 9 10 11 12
| $qb = $this->getEntityManager()
->createQuery("
SELECT e,
b,
SUM(e.montantCredit) AS sa__montantCredit,
SUM(e.montantDebit) AS sa__montantDebit
FROM MyAppComptabiliteBundle:Ecriture e
LEFT JOIN e.budget b
WHERE ".$params[0]."
GROUP BY e.numero_sectionAnalytique
ORDER BY e.numero_sectionAnalytique
"); |
J'ai crée mes entités comme je pense être le mieux et lors de la commande
doctrine:schema:update --force
j'ai une erreur qui est généré :
1 2 3
| Updating database schema...
[PDOException]
SQLSTATE[HY000]: General error: 1005 Can't create table 'compta.#sql-b84_86' (errno: 150) |
j'ai ensuite fait un
doctrine:schema:update --dump-sql
ce qui m'a donné :
ALTER TABLE ecriture ADD CONSTRAINT FK_FA7FEFBD791E1EFF27C98473 FOREIGN KEY (numero_sectionAnalytique, numero_service) REFERENCES Budget(numero_sectionAnalytique, numero_service)
j'ai tenté de l'inserer directement dans ma base via SQL et je me retrouve avec la même erreur si ce n'est le nom de la table
#1005 - Can't create table 'compta.#sql-b84_83' (errno: 150)
Voici mes différentes entités :
Ecriture, représente une écriture comptable identifié par son id.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| /**
* @ORM\Entity
* @ORM\Entity(repositoryClass="MyApp\ComptabiliteBundle\Repository\EcritureRepository")
*/
class Ecriture
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string", length=15)
*/
protected $numero_service;
/**
* @ORM\Column()
*/
protected $intitule_service;
/**
* @ORM\Column(type="string", length=15)
*/
protected $numero_sectionAnalytique;
/**
* @ORM\Column()
*/
protected $intitule_sectionAnalytique;
/**
* @ORM\ManyToOne(targetEntity="MyApp\ComptabiliteBundle\Entity\Budget", inversedBy="ecritures")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="numero_sectionAnalytique", referencedColumnName="numero_sectionAnalytique"),
* @ORM\JoinColumn(name="numero_service", referencedColumnName="numero_service")
* })
*/
protected $budget;
.
.
.
} |
Budget, représente un budget identifié par un numéro de service, une section analytique et une année.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| /**
* @ORM\Entity
*/
class Budget
{
/**
* @ORM\Id
* @ORM\Column(type="string", length=15)
*/
protected $numero_service;
/**
* @ORM\Id
* @ORM\Column(type="string", length=15)
*/
protected $numero_sectionAnalytique;
/**
* @ORM\Id
* @ORM\Column(type="integer")
*/
protected $annee;
/**
* @ORM\OneToMany(targetEntity="MyApp\ComptabiliteBundle\Entity\Ecriture", mappedBy="budget")
*/
protected $ecritures;
/**
* @ORM\Column(type="decimal", scale=2, precision=10)
*/
protected $montantCharges;
/**
* @ORM\Column(type="decimal", scale=2, precision=10)
*/
protected $montantRecettes;
.
.
.
} |
quelqu'un est-il déjà tombé sur un cas de figure comme ça?
Peut-être que je me suis trompé dans la manière de joindre mes tables?
Merci de votre aide!
Partager