0
votes

i learn Symfony and Doctrine with Jobeet. I would like add relation in JobeetJob. this is original: http://www.symfony-project.org/jobeet/1_4/Doctrine/en/03

I do like this:

JobeetCategory:
  actAs: { Timestampable: ~ }
  columns:
    name: { type: string(255), notnull: true, unique: true }

JobeetCategorya:
  actAs: { Timestampable: ~ }
  columns:
    name: { type: string(255), notnull: true, unique: true }

JobeetJob:
  actAs: { Timestampable: ~ }
  columns:
    category_id:  { type: integer, notnull: true }
    categorya_id:  { type: integer, notnull: true }
    type:         { type: string(255) }
    (...)
    expires_at:   { type: timestamp, notnull: true }
  relations:
    JobeetCategory: { onDelete: CASCADE, local: category_id, foreign: id, foreignAlias: JobeetJobs }
    JobeetCategorya: { onDelete: CASCADE, local: categorya_id, foreign: id, foreignAlias: JobeetJobsa }

when i do:

php symfony doctrine:build --all --and-load

i have error

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (jobeet.jobeet_job, CONSTRAINT jobeet_job_categorya_id_jobeet_categorya_id FOREIGN KEY (categorya_id) REFERENCES jobeet_categorya (id) ON DELETE CASCADE)

why?

1
Patrick, you should formulate your title as a question and as Jobeet is symfony/doctrine, put that in there as well. This helps that others will spot a question they can probably answer. Just a suggestion: How to create a relation in Doctrine?hakre
What do you do, when you get the error?hakre
i do: php symfony doctrine:build --all --and-loadPatrick Campbell
Add that into your question like: When I do doctrine:build --all --and-load then I get this error: (your error message is already in the question so put it in between)hakre
ok :) may know the solution to the problem?Patrick Campbell

1 Answers

1
votes

I'm thinking the problem is caused by the --and-load part of that command. That error comes up often when you're loading fixtures into tables in an order that would violate their foreign key relationships (i.e. putting child data in before parent data).

If this is indeed your problem, you can find several threads here on how to work around this issue... basically, by just building first (build --all), and then loading fixtures in separate batches so they respect the foreign key relationships.