1
votes

I'm using symfony 1.4 and Propel as ORM. I have a form that needs to embed some other form in it. The other form is n:m relation that connects customer and some object. I can't find out how to embed it so that it displays all the objects for a customer.

Considering the following schema, I want to embed CustomerCountryGroup form in Customer form to display a list of CuountryGroup objects related to a user.

Here is my schema.yml:

Customer:
  _attributes: { phpName: Customer }
  id:
    phpName: Id
    type: INTEGER
    size: '11'
    primaryKey: true
    autoIncrement: true
    required: true

CustomerCountryGroup:
  _attributes: { phpName: CustomerCountryGroup }
  id:
    phpName: Id
    type: INTEGER
    size: '10'
    primaryKey: true
    autoIncrement: true
    required: true
  customerId:
    phpName: CustomerId
    type: INTEGER
    size: '10'
    required: false
    foreignTable: Customers
    foreignReference: id
    onDelete: CASCADE
    onUpdate: RESTRICT
  countryGroupId:
    phpName: CountryGroupId
    type: INTEGER
    size: '10'
    required: false
    foreignTable: CountryGroups
    foreignReference: id
    onDelete: CASCADE
    onUpdate: RESTRICT

CountryGroup:
  _attributes: { phpName: CountryGroup }
  id:
    phpName: Id
    type: INTEGER
    size: '11'
    primaryKey: true
    autoIncrement: true
    required: true

Do you know where I can find some tutorial/solution of this problem?

Many thanks

1

1 Answers

2
votes

Symfony should generate multiple selects for you, if that's what you mean by embedded. This, as opposed to actually being able to edit Countries from a Customer. I believe you need to set the IDs in the reference table as PKs, then symfony will do its thing:

CustomerCountryGroup:
  _attributes: { phpName: CustomerCountryGroup }
  customerId:
    phpName: CustomerId
    type: INTEGER
    required: true
    primaryKey: true
    foreignTable: Customers
    foreignReference: id
    onDelete: CASCADE
    onUpdate: CASCADE
  countryGroupId:
    phpName: CountryGroupId
    type: INTEGER
    required: true
    primaryKey: true
    foreignTable: CountryGroups
    foreignReference: id
    onDelete: CASCADE
    onUpdate: CASCADE