Doctrine 1
  1. Doctrine 1
  2. DC-447

Problem linking many-to-many relationships

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.1
    • Fix Version/s: None
    • Component/s: Relations
    • Labels:
      None
    • Environment:
      Windows Vista x86 SP2, PHP 5.2.x

      Description

      Hello,

      Here's a small usage example of linking many-to-many relationships. The group is not linked with the user after calling link() as can be seen by comparing the group ids before and after the call.

      schema.yml
      User:
        tableName: users
        columns:
          username:      { type: string(255), notnull: true }
          email:         { type: string(255), notnull: true }
        indexes:
          username_idx:
            fields: [username]
            type:   unique
          email_idx:
            fields: [email]
            type:   unique
        actAs: [Timestampable]
        relations:
          groups:
            class:    Group
            alias:    Groups
            refClass: UserGroupRelation
      
      Group:
        tableName: groups
        columns:
          name: { type: string(255), notnull: true }
        actAs: [Timestampable, NestedSet]
        relations:
          users:
            class:    User
            alias:    Users
            refClass: UserGroupRelation
      
      UserGroupRelation:
        tableName: user_group_relations
        columns:
          user_id:  { type: integer, notnull: true, primary: true }
          group_id: { type: integer, notnull: true, primary: true }
        relations:
          Group:
            class:        Group
            foreignAlias: UserGroupRelations
            onDelete:     CASCADE
          User:
            class:        User
            foreignAlias: UserGroupRelations
            onDelete:     CASCADE
      
      test.php
      $u = Doctrine_Core::getTable('User')->findOneByUsername('james');
      $g = Doctrine_Core::getTable('Group')->findOneByName('group');
      var_dump($g['id']);
      $current = array();
      foreach ($u['UserGroupRelations'] as $r) {
          $current[] = $r['group_id'];
      }
      var_dump($current);
      $u->link('Groups', array($g['id']), true);
      $u = Doctrine_Core::getTable('User')->findOneByUsername('james');
      $current = array();
      foreach ($u['UserGroupRelations'] as $r) {
          $current[] = $r['group_id'];
      }
      var_dump($current);
      
      Output
      string(1) "2"
      array(3) {
        [0]=>
        string(1) "1"
        [1]=>
        string(1) "5"
        [2]=>
        string(1) "6"
      }
      array(3) {
        [0]=>
        string(1) "1"
        [1]=>
        string(1) "5"
        [2]=>
        string(1) "6"
      }
      

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Rytis Daugirdas
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: