0
votes

I just started to use the PHP symfony framework. Currently I'm trying to create fixture files in YAML to easily insert data into my MySQL database.

Now my database has a couple of relations, I have the tables Organisation and Location.

Organisation
 org_id (PK)
 org_name

Location
 loc_id (PK)
 org_id (FK)
 loc_name

Now I'm trying too link these tables in my fixture file, but for the life of me I cannot figure out how. Since the org_id is auto-incremented I can't simply use

org_id: 1

In the location fixture.

How can I fix this?

1

1 Answers

0
votes

You re-use the textual id you gave to the organisation in the fixture (which is just an identifier in the YAML file, it has nothing to do with how it ends up in the database). Since org_id and (I presume) loc_id are auto-generated, you leave them out. Like this:

Organisation:
  apple:
    org_name: "Apple"
  banana:
    org_name: "Banana"

Location:
  apple_loc_1:
    loc_name: "Apple Location #1"
    org_id: apple
  apple_loc_2:
    loc_name: "Apple Location #2"
    org_id: apple
  banana_loc_1:
    loc_name: "Banana Location"
    org_id: banana