Doctrine 1
  1. Doctrine 1
  2. DC-765

Incorrect query for inherited many-to-many relation

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      PHP Version 5.3.0
      System Windows NT ZEUS 5.1 build 2600 (Windows XP Professional Service Pack 3) i586
      symfony version 1.4.6-DEV
      sfDoctrinePlugin revision 29679

      Description

      Column Aggregation Inheritance, Many to Many

      Inspired by post on symfonyexperts.com (http://symfonyexperts.com/question/show/id/48) I tried to setup a similar scenario whith 1 'Entity' Model and many-to-many relations between them.
      The different types of relations between them are implemented by inheritance.

      It seems that Doctrine is omitting the type of the key field in the generated queries.
      I put up an example to reproduce it:

      Model (YAML)
      ---------------------------------------
      Entity:
      columns:
      name:

      { type: varchar(20) }

      relations:
      Owners:

      { class: Entity, local: src_entity_id, foreign: dst_entity_id, refClass: EntityRelationOwner }

      Compatibles:

      { class: Entity, local: src_entity_id, foreign: dst_entity_id, refClass: EntityRelationCompatible }

      EntityRelation:
      columns:
      src_entity_id:

      { type: integer(4), primary: true }

      dst_entity_id:

      { type: integer(4), primary: true }

      type:

      { type: string(10) }

      EntityRelationOwner:
      inheritance:
      extends: EntityRelation
      type: column_aggregation
      keyField: type
      keyValue: owner

      EntityRelationCompatible:
      inheritance:
      extends: EntityRelation
      type: column_aggregation
      keyField: type
      keyValue: compatible

      Action:
      ---------------------------------------
      ..
      $entity = Doctrine::getTable('Entity')->find(1);
      $entity->getOwners()
      ..

      SQL:
      ---------------------------------------
      SELECT entity.id AS entity__id,
      entity.name AS entity__name,
      entity_relation.src_entity_id AS entity_relation__src_entity_id,
      entity_relation.dst_entity_id AS entity_relation__dst_entity_id,
      entity_relation.type AS entity_relation__type
      FROM entity
      INNER JOIN entity_relation ON entity.id = entity_relation.dst_entity_id
      WHERE entity.id IN (
      SELECT dst_entity_id FROM entity_relation WHERE src_entity_id = '1'
      )
      ORDER BY entity.id ASC

      To my understanding, the inner SQL statement is missing the type restriction and should be:

      SELECT dst_entity_id FROM entity_relation WHERE src_entity_id = '1' AND type = 'owner'

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Jorgo Miridis
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: