This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use the new forum.
Home » support » symfony 1.3 and 1.4 » schema.yml relation type problem
schema.yml relation type problem [message #102506] Thu, 15 July 2010 09:31 Go to next message
osama  is currently offline osama
Messages: 4
Registered: September 2007
Junior Member
Hello,
I have my database schema defined in YML format. All table relations are correctly created with "symfony doctrine:build" task, except of Reservation - Plane relation. This is my definition of above tables:

Plane:
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true
    name:
      type: varchar(64)
      notnull: true
    active:
      type: boolean
      notnull: true
      default: true
    type_id:
      type:      integer(4)
      primary:   true
    price_id:
      type:      integer(4)
      primary:   true
  relations:
    PlaneType:
      local: type_id
      foreignType: one
      foreignAlias: Type
    Price:
      local: price_id
      foreignType: one
      foreignAlias: Price

Reservation:
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true
    user_id:
      type: integer(4)
      notnull: true
    plane_id:
      type: integer(4)
      notnull: true
    reservation_status_id:
      type: integer(4)
      notnull: true
      default: 1
    start_date:
      type: time
      notnull: true
    end_date:
      type: time
      notnull: true
  relations:
    sfGuardUser:
      local: user_id
      foreignType: one
      foreignAlias: User
    ReservationStatus:
      local: reservation_status_id
      foreignType: one
      foreignAlias: Status
    Plane:
      local: plane_id
      onDelete: CASCADE
      foreignType: one
      foreignAlias: Plane


Reservation should be related to Plane with FK in `reservation` table, by `reservation`.`plane_id` field. After calling "symfony doctrine:build ..." task foreign keys are created in both tables. FK doesn't need to exist in `plane` table. Obviously inserting any data into those tables results in error message:

Quote:

Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails


I use MySQL 5.1.41 and symfony 1.4.7-DEV. Please help me with correct table definition, with one-direction relation. Other relations defined in the same way, are created correctly. Thank You for any advices.
Re: schema.yml relation type problem [message #102570 is a reply to message #102506 ] Fri, 16 July 2010 10:03 Go to previous message
osama  is currently offline osama
Messages: 4
Registered: September 2007
Junior Member
After some research I've noticed something. From my schema.yml I removed all other tables and relations, except of Plane and Reservation. Foreign key in `plane` table was still created. But when I commented out two fields in Plane schema declaration, then everything goes fine and relation is correctly created. Here is properly working, minified schema:

Plane:
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true
    name:
      type: varchar(64)
      notnull: true
#    type_id:
#      type:      integer(4)
#      primary:   true
#    price_id:
#      type:      integer(4)
#      primary:   true
    active:
      type: boolean
      notnull: true
      default: true

Reservation:
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true    
    start_date:
      type: time
      notnull: true
    end_date:
      type: time
      notnull: true
    plane_id:
      type: integer(4)
  relations:
    Plane:
      foreignType: one

Do You have any ideas, why is this happening? Thanks in advance.
Regards.
Previous Topic:configuring component slots
Next Topic:Session timeout and ajax calls
Goto Forum:
  

powered by FUDforum - copyright ©2001-2004 FUD Forum Bulletin Board Software