Ticket #796 (closed defect: fixed)

Opened 17 months ago

Last modified 16 months ago

Record hydrates as wrong class 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 (last modified by dbrewer) (diff)

Summary of issue:

In some cases, when you do a select from a class which is the parent class used in column aggregation inheritance, you get back the parent class rather than the appropriate child. This behavior is different from what it was in 0.9.

Details:

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

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 results of the following code are different in 0.9 and 0.10.

$resource = Doctrine_Query::create()
    ->from('Resource')
    ->where("Resource.id=?", $id)
    ->execute()
    ->getFirst();

# returns 'Record' in 0.9, 'Resource' in 0.10.  
echo get_class($resource);

I believe the correct result should be to return 'Record'.

Change History

Changed 17 months ago by dbrewer

  • description modified (diff)

Changed 17 months ago by dbrewer

  • description modified (diff)

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.