Hi 

I have an existing project which I am migrating to Doctrine

The schema , which I cannot easily change, revolves around an order table 
which has an integer id primary key

The products and addresses tables have an orderid foreign key on the order 
table id.

The shops table has a varchar(20) idname column which is mapped to a 
varchar(20) idshop  column (foreign key)in orders.

The idname is nullable as the shop may be set later.

This last bit causes the problem.

I have created the yaml files for orders, products and addressses and the 
entities and database are generated OK.

However the shop does not generate the required getter and setter for shop 
in the order entity and the database is not created due to a General error: 
1215 Cannot add foreign key constraint error

Please see below the YAML

I cannot see why this is not working - Help!

 config/yaml/Order.dcm.yml

Order:
  type: entity
  table: orders
  id:
    id:
      type: integer
      generator:
        strategy: AUTO
  
  fields:
      ordercode:
          type: string
          length: 20
      idshop:
          type: string
          length: 20
          
  oneToOne:
    product:
      targetEntity: Product
      mappedBy: order
      
  oneToOne:
    shop:
      targetEntity: Shop
      mappedBy: order
  
  oneToMany:
    addresses:
      targetEntity: Address
      mappedBy: order

  
# config/yaml/Product.dcm.yml

Product:
  type: entity
  table: products
  id:
    id:
      type: integer
      generator:
        strategy: AUTO
  fields:
      productcode:
          type:   string
          length: 10
      description:
          type:   string
          length: 20

  oneToOne:
    order:
      targetEntity: Order
      inversedBy: product
      joinColumn:
        name: orderid
        referencedColumnName: id

# config/yaml/Shop.dcm.yml

Shop:
    type:   entity
    table:  shops
    id:
        id:
            type:   integer
            generator:
                strategy:   AUTO
    fields:
        idname:
            type:   string
            length: 20
        description:
            type:   string
            length: 50
    
    oneToOne:
      order:
        targetEntity: Order
        inversedBy: shop
        joinColumn:
          name: idname
          referencedColumnName: idshop


# config/yaml/Address.dcm.yml
Address:
    type:   entity
    table:  addresses
    id:
        id:
            type:   integer
            generator:
                strategy:   AUTO
    fields:
        addresstype:
            type:   string
            length: 20
        addressid:
            type:   string
            length: 30
        addressname:
            type:   string
            length: 40
        addressline1:
            type:   string
            length: 40
        addressline2:
            type:   string
            length: 40
    
    manyToOne:
        order:
            targetEntity:   Order
            inversedBy:   addresses
            joinColumn:
                name: orderid
                referencedColumnName: id   

-- 
You received this message because you are subscribed to the Google Groups 
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to