开发者

Symfony + doctrine + one-to-many relationships

开发者 https://www.devze.com 2022-12-21 22:03 出处:网络
I need a one-to-many relationships for my sf 1.4 + doctrine 1.2 project. I copied the relation just like this:

I need a one-to-many relationships for my sf 1.4 + doctrine 1.2 project. I copied the relation just like this:

User:
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true
    contact_id:
      type: integer(4)
    username:
      type: string(255)
    password:
      type: string(255)

Phonenumber:
  columns:
    id:
      type: integer(4)
      primary: true
      autoincrement: true
    name:
      type: string(255)
    user_id:
      type: integer(4)
  relations:
    User:
      foreignAlias: Phonenumbers

Then, I rebuild my schema, and generate the backend modules for User and Phonenumber.

In the Phonenumber admin panel, I can set the user by a select box with Users. But in the User admin panel I do not have a list with the phonenumbers to allow users to select multiple phonenumbers to the user. How can I add t开发者_如何学Che many relation here?


I prefer to do it this way round as it's likely that your user will have many relations and not phonenumbers, so this keeps it all in one place....

In your User:

relations:
   Phonenumber:
     class: Phonenumber  // model name for relation
     local: id           // key in this table
     foreign: id         // key in the referenced table
     type: many          // User has MANY phonenumbers
     foreignType: one    // Phonenumber has ONE user
     alias: Phonenumber  // What a user calls Phonenumber
     foreignAlias: User  // What a Phonenumber calls User

Given that you're declaring the "id" for both tables instead of allowing Doctrine to create them automatically, you may need to include the "local" and "foreign"... havent tested.

0

精彩评论

暂无评论...
验证码 换一张
取 消