views:

142

answers:

1

Hi All,

I'm setting up my first symfony project, and am having trouble with the schema. I'm not sure if I'm going about it the right way.

I'm having a problem with two of my classes. I have Clients, which can have many Contacts, one of the contacts needs to be selected as the invoice contact. This is my schema:

NativeClient:
  actAs: { Timestampable: ~ }
  columns:
    name:                { type: string(255), notnull: true }
    address:             { type: string(255) }
    postcode:            { type: string(9) }
    tel:                 { type: string(50) }
    fax:                 { type: string(50) }
    website:             { type: string(255) }
    client_status_id:    { type: integer, notnull: true, default: 0 }
    priority:            { type: boolean, notnull: true, default: 0 }
    invoice_contact_id:  { type: integer }
    invoice_method_id:   { type: integer }
  relations:
    NativeContact:       { local: invoice_contact_id, foreign: id, foreignAlias: NativeInvoiceContacts }
    NativeClientStatus:  { local: client_status_id, foreign: id, foreignAlias: NativeContacts }
    NativeInvoiceMethod: { local: invoice_method_id, foreign: id, foreignAlias: NativeClientStatuses }


NativeContact:
  actAs: { Timestampable: ~ }
  columns:
    client_id:          { type: integer, notnull: true }
    name:               { type: string(255), notnull: true }
    position:           { type: string(255) }
    tel:                { type: string(50), notnull: true }
    mobile:             { type: string(50) }
    email:              { type: string(255) }
  relations:
    NativeClient:       { onDelete: CASCADE, local: client_id, foreign: id, foreignAlias: NativeClients } 

NativeClientStatus:
  actAs: { Timestampable: ~ }
  columns:
    name:               { type: string(255), notnull: true }

NativeInvoiceMethod:
  actAs: { Timestampable: ~ }
  columns:
    name:               { type: string(255), notnull: true }

If i remove the following line (and associated fixtures) it works, otherwise I get a segmentation fault.

NativeContact:       { local: invoice_contact_id, foreign: id, foreignAlias: NativeInvoiceContacts }

Could it be getting in a loop? Trying to reference the Client and the Contact over and over? Any help would be greatly appreciated! Thanks!

Darren

A: 

Darren, it seems like you're defining the relationship at both ends while using conflicting criteria...

NativeContact:       { local: invoice_contact_id, foreign: id, foreignAlias: NativeInvoiceContacts }

...relationship is between "invoice_contact_id" and undeclared "id" PK in NativeContact.

 NativeClient:       { onDelete: CASCADE, local: client_id, foreign: id, foreignAlias: NativeClients } 

... same relationship is between "client_id" and undeclared "id" PK in NativeClient.

I personally only define these in one end and let Doctrine handle the rest, but it depends on what you're trying to achieve here. If ONE client HAS MANY contacts, you could drop the second declaration and define the relationship in the clients table only and add "type: many, foreignType: one" to state that it's a one-to-many relationship.

Tom
OK, so it looks like I'm going about it the wrong way. Is there a getting the following structure: - There are many Clients; - Each Client can have many Contacts; - One of those Contacts can be the Invoice Contact; Will I need to use a bridge Class, like ClientInvoiceContact, which has the ID of the Client and Contact in only? That just sounds superfluous, when the Client could store the Contact ID in it. I know it could be seen as a circular reference, which is probably where the code is having difficulties, but in essence I'm wanting to set one of the Contacts as 'primary'.
dazhall