Ticket #797 (closed defect: fixed)

Opened 17 months ago

Last modified 16 months ago

Problems with relationship hydration when using column aggregation inheritence

Reported by: dbrewer Owned by: jwage
Priority: minor Milestone: 0.10.3
Component: Inheritance Version: 0.10.0
Severity: Keywords:
Cc: Has Test:
Status: Has Patch:

Description

Summary of issue:

There appear to be problems with relationship hydration when using column aggregation inheritence. In some cases, you can end up with an object which appears to be of the subclass you are expecting but does not have the appropriate relationships defined for it. This used to work in 0.9 but is broken in 0.10.

This is really hard to explain without a concrete example, so bear with me.

Details:

I have a schema which looks (in part) like this:

Comment:
  package: armCommentPlugin.lib.model.doctrine
  tableName: comments
  columns:
    id: {type: integer, primary: true, autoincrement: true}
    resource_id: {type: integer}
    user_id: {type: integer}
    parent_comment_id: {type: integer}
    title: {type: string, length: 255}
    comment: {type: string}
    xpos: {type: integer}
    ypos: {type: integer}
    poster_name: {type: string, length: 255}
    is_approved: {type: boolean, default: false}
  actAs:
    Timestampable:
      created:
        name: created_at
        type: timestamp
      updated:
        name: updated_at
        type: timestamp
  relations:
    Resource:
      foreignAlias: Comments
      local: resource_id
      foreign: id
      onDelete: cascade
    User:
      foreignAlias: Comments
      local: user_id
      foreign: id
      onDelete: set null
    ParentComment:
      class: Comment
      foreignAlias: ChildComments
      local: parent_comment_id
      foreign: id
      onDelete: set null

Resource:
  package: armResourcePlugin.lib.model.doctrine
  tableName: resources
  columns:
    id: {type: integer, primary: true, autoincrement: true}
    resource_type_id: {type: integer}
    primary_asset_id: {type: integer}
    owner_id: {type: integer}
    title: {type: string, length: 255}
    description: {type: string}
    view_count: {type: integer, default: 0}
  actAs:
    Timestampable:
      created:
        name: created_at
        type: timestamp
      updated:
        name: updated_at
        type: timestamp
  indexes:
    title:
      fields:
        title:
          sorting: ASC
          length: 20
    resource_type_id:
      fields:
        resource_type_id: [ ]
    primary_asset_id:
      fields:
        primary_asset_id: [ ]
  relations:
    ResourceType:
      local: resource_type_id
    PrimaryAsset:
      class: Asset
      local: primary_asset_id
      foreignAlias: Resources
      onDelete: set null

ResourceType:
  package: armResourcePlugin.lib.model.doctrine
  tableName: resource_types
  columns:
    name: {type: string, length: 45}

Record:
  package: armRecordPlugin.lib.model.doctrine
  inheritance: {extends: Resource, keyField: resource_type_id, keyValue: 2}
  tableName: resources

RecordContent:
  package: armRecordPlugin.lib.model.doctrine
  tableName: records
  columns:
    id: {type: integer, primary: true, autoincrement: true}
    resource_id: {type: integer, unique: true}
    record_type_id: {type: integer}
    title: {type: string, length: 255}
    description: {type: string}
  relations:
    Record:
      class: Record
      local: resource_id
      foreignAlias: Content
      foreignType: one
      onDelete: cascade
    RecordType:
      local: record_type_id
      foreignAlias: Records
  indexes:
    resource_id:
      fields:
        resource_id: [ ]
      type: unique
    record_type_id:
      fields:
        record_type_id: [ ]

RecordType:
  package: armRecordPlugin.lib.model.doctrine
  tableName: record_types
  columns:
    id: {type: integer, primary: true, autoincrement: true}
    name: {type: string, length: 50}

To summarize the schema, there is a Resource record class which defines shared fields for a number of subclasses, including Record (shown above) and Asset (not shown). The Comment record class is related to Resource, allowing Comments to be placed on any type of resource. When you get back a list of Resources for the comment, it is expected that they should come back hydrated as the appropriate subclass.

The following code demonstrates how I am loading a comment, and the difference in behavior between 0.9 and 0.10.

$comment = Doctrine_Query::create()->query('
    FROM Comment c
    WHERE c.id=?
', array($id))->getFirst();

# the following code throws an exception in 0.10 but works in 0.9
$title = $comment['Resource']['Content']['title'];

The exception that is thrown:

Doctrine_Record_Exception: Unknown record property / related component "Content" on "Asset" in /var/project/www/iqsc/plugins/sfDoctrinePlugin/lib/doctrine/lib/Doctrine/Record/Filter/Standard.php on line 55

Change History

Changed 16 months ago by jwage

  • milestone set to 0.10.2

Changed 16 months ago by jwage

  • milestone changed from 0.10.2 to 0.10.3

Changed 16 months ago by jwage

  • status changed from new to closed
  • resolution set to fixed

(In [3961]) fixes #796 fixes #797

Note: See TracTickets for help on using tickets.