开发者

How to create a relation in Doctrine

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/开发者_StackOverflowDoctrine/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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜