2017-12-03 6 views
0

Ich habe Probleme beim Erstellen von SingleCase mit CaseCollectionsCaseMap.Symfony manyToOne bei Flush-Fehler

Dies ist meine db Struktur:

CREATE TABLE cases (
    ca_id serial NOT NULL, 
    ca_parent_id INTEGER, 
    ca_urlcode VARCHAR(255) NOT NULL, 
    ca_defaultcollection_id INTEGER, 
    ca_active SMALLINT NOT NULL DEFAULT 1, 
    ca_author_id INTEGER, 
    ca_author_name VARCHAR(255) NOT NULL, 
    ca_modified timestamp without time zone NOT NULL DEFAULT now(), 
    ca_created timestamp without time zone NOT NULL DEFAULT now(), 
    CONSTRAINT cases_pk PRIMARY KEY (ca_id), 
    CONSTRAINT cases_ca_parent_id FOREIGN KEY (ca_parent_id) 
     REFERENCES cases (ca_id) MATCH SIMPLE 
     ON UPDATE NO ACTION ON DELETE SET NULL 
) 
WITH (
    OIDS=FALSE 
); 

CREATE TABLE case_collections (
    cc_id serial NOT NULL, 
    cc_parent_id INTEGER, 
    cc_urlcode VARCHAR(255) NOT NULL, 
    cc_active smallint NOT NULL DEFAULT 1, 
    cc_priority INTEGER DEFAULT 0 NOT NULL, 
    cc_author_id INTEGER, 
    cc_author_name VARCHAR(255) NOT NULL, 
    cc_modified timestamp without time zone NOT NULL DEFAULT now(), 
    cc_created timestamp without time zone NOT NULL DEFAULT now(), 
    CONSTRAINT case_collections_pk PRIMARY KEY (cc_id), 
    CONSTRAINT case_collections_cc_parent_id FOREIGN KEY (cc_parent_id) 
     REFERENCES case_collections (cc_id) MATCH SIMPLE 
     ON UPDATE NO ACTION ON DELETE SET NULL 
) 
WITH (
    OIDS=FALSE 
); 

CREATE TABLE case_collections_cases (
    cc_id INTEGER NOT NULL, 
    ca_id INTEGER NOT NULL, 
    ccca_priority INTEGER NOT NULL, 
    CONSTRAINT case_collections_cases_pk PRIMARY KEY (cc_id, ca_id), 
    CONSTRAINT case_collections_cases_cc_id_fk FOREIGN KEY (cc_id) 
     REFERENCES case_collections (cc_id) MATCH SIMPLE 
     ON UPDATE NO ACTION ON DELETE CASCADE, 
    CONSTRAINT case_collections_cases_ca_id_fk FOREIGN KEY (ca_id) 
     REFERENCES cases (ca_id) MATCH SIMPLE 
     ON UPDATE NO ACTION ON DELETE CASCADE 
) 
WITH (
    OIDS=FALSE 
); 

Dies ist meine Lehre ORM-Dateien:

PPK\Domain\Entity\SingleCase\SingleCase: 
    type: entity 
    repositoryClass: PPK\Infrastructure\Repository\SingleCase\DoctrineSingleCaseRepository 
    table: cases 

    id: 
    caId: 
     type: integer 
     column: ca_id 
     generator: 
     strategy: SEQUENCE 
     sequence-generator: 
     allocationSize: 1 
     initialValue: 1 
     sequenceName: cases_case_id_seq 

    fields: 
    caUrlcode: 
     type: string 
     length: 255 
     column: ca_urlcode 
    caActive: 
     type: smallint 
     column: ca_active 
    caAuthorId: 
     type: integer 
     column: ca_author_id 
    caAuthorName: 
     type: string 
     column: ca_author_name 
    caModified: 
     type: datetime 
     column: ca_modified 
    caCreated: 
     type: datetime 
     column: ca_created 

    manyToOne: 
    defaultCollection: 
     targetEntity: PPK\Domain\Entity\SingleCase\CaseCollectionsCaseMap 
     joinColumns: 
     ca_defaultcollection_id: 
      referencedColumnName: cc_id 
     ca_id: 
      referencedColumnName: ca_id 

PPK\Domain\Entity\SingleCase\CaseCollectionsCaseMap: 
    type: entity 
    repositoryClass: PPK\Infrastructure\Repository\SingleCase\DoctrineCaseCollectionsCaseMapMapRepository 
    table: case_collections_cases 

    id: 
    collection: 
     type: integer 
     column: cc_id 
     associationKey: true 
    singleCase: 
     type: integer 
     column: ca_id 
     associationKey: true 

    fields: 
    cccaPriority: 
     type: integer 
     column: ccca_priority 

    manyToOne: 
    singleCase: 
     targetEntity: PPK\Domain\Entity\SingleCase\SingleCase 
     joinColumns: 
      ca_id: 
       referencedColumnName: ca_id 
     orphanRemoval: false 

    collection: 
     targetEntity: PPK\Domain\Entity\CaseCollection\CaseCollection 
     joinColumns: 
      cc_id: 
       referencedColumnName: cc_id 
     orphanRemoval: false 


PPK\Domain\Entity\CaseCollection\CaseCollection: 
    type: entity 
    repositoryClass: PPK\Infrastructure\Repository\CaseCollection\DoctrineCaseCollectionRepository 
    table: case_collections 

    id: 
    ccId: 
     type: integer 
     column: cc_id 
     generator: { strategy: AUTO } 

    fields: 
    ccUrlcode: 
     type: string 
     length: 255 
     column: cc_urlcode 
    ccActive: 
     type: smallint 
     column: cc_active 
    ccPriority: 
     type: integer 
     column: cc_priority 
    ccAuthorId: 
     type: integer 
     column: cc_author_id 
    ccAuthorName: 
     type: string 
     column: cc_author_name 
    ccModified: 
     type: datetime 
     column: cc_modified 
    ccCreated: 
     type: datetime 
     column: cc_created 

In meinem Command ich SingleCase Repo mit CaseCollectionsCase Repo injiziert haben.

Wenn ich nur erstellen SingleCase:

$singleCase = new SingleCase(); 
$singleCase->setCaActive($singleCaseDTO->getStatus()); 
$singleCase->setCaUrlcode($singleCaseDTO->getUrl()); 
$singleCase->setCaAuthorId($user->getUsrId()); 
$singleCase->setCaAuthorName($user->getUsrName()); 
$singleCase->setCaCreated(); 
$singleCase->setCaModified(); 
$this->singleCaseRepository->create($singleCase); 

Lehre wirft Fehler:

SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "ca_id" violates not-null constraint 
DETAIL: Failing row contains (null, null, /new-question, null, 0, 1, XX, 2017-12-03 13:22:18, 2017-12-03 13:22:18). 

CaseCollectionsCaseMap Hinzufügen noch nicht hilft:

$defaultCollection = new CaseCollectionsCaseMap(); 
$defaultCollection->setCollection($cc); 
$defaultCollection->setCccaPriority(0); 

$singleCase->setDefaultCollection($defaultCollection); 
$this->singleCaseRepository->create($singleCase); 

Lehre wirft:

A new entity was found through the relationship 'PPK\Domain\Entity\SingleCase\SingleCase#defaultCollection' that was not configured to cascade persist operations for entity 

Und wenn ich hinzufügen Kaskade: [ "anhalten", "merge"] zu defaultCollection Lehre wirft:

An exception occurred while executing 'INSERT INTO cases (ca_id, ca_urlcode, ca_active, ca_author_id, ca_author_name, ca_modified, ca_created, ca_parent_id, ca_defaultcollection_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)' with params [null, "\/new-question", 0, 1, "XX", "2017-12-03 13:26:26", "2017-12-03 13:26:26", null, null] 

Berufung bestehen $ Caid erzeugt, aber Spülung ist es nulling.

Jede Hilfe wird sehr geschätzt.

Antwort

0

Welche db verwenden Sie? Wenn es nicht MySQL ist, schlage ich vor, dass Sie die Generierungsstrategie "AUTO" für Ihre IDs verwenden. Um herauszufinden, welche dbs nicht unterstützen "AUTO" Strategie sehen http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#identifier-generation-strategies


UPDATE: sorry habe einen Fehler gemacht. Anscheinend Doktrin immer noch verwendet SEQUENCE Strategie, wenn Sie AUTO angeben, obwohl es besagt, dass SEQUENCE nicht für Postgres unterstützt wird. Ich konnte dies aus dieser Ausgabe https://github.com/doctrine/doctrine2/issues/6429 herausfinden. Davon ausgehend sollten Sie die ID-Strategie explizit auf IDENTITY setzen. Tut mir leid, dass ich dich früher falsch informiert habe.

+0

Ich benutze PostgreSQL 9.6. Das Ändern des Generators auf AUTO hat keine Auswirkung. – msmolik

+0

Sorry, ein Fehler gemacht. Sie müssen 'IDENTITY' verwenden. Wird meine Antwort jetzt aktualisieren – avpav

+0

Noch keinen Effekt. – msmolik