Ticket #1341 (closed defect: fixed)

Opened 11 months ago

Last modified 9 months ago

Problem with relations & column aliases

Reported by: ishtanzar Owned by: romanb
Priority: minor Milestone: 1.0.4
Component: Query/Hydration Version: 1.0.0
Severity: Keywords: relation, alias, column
Cc: Has Test: no
Status: Pending Core Response Has Patch: no

Description

From  this discussion.

When using the attached classes with this code :

Doctrine_Query::create()
    ->from("Episode ep")
    ->leftJoin("ep.team t")
    ->execute();

Gives the following exception :

        Fatal error:  Uncaught exception 'Doctrine_Record_Exception' with message 'Unknown property team_teamId' in /Users/ishtanzar/Sites/_library/Doctrine-0.11.1/Doctrine/Record.php:813
        Stack trace:
        #0 /Users/ishtanzar/Sites/_library/Doctrine-0.11.1/Doctrine/Record.php(1021): Doctrine_Record->rawGet('team_teamId')
        #1 /Users/ishtanzar/Sites/_library/Doctrine-0.11.1/Doctrine/Record.php(949): Doctrine_Record->coreSetRelated('team', Object(Team))
        #2 /Users/ishtanzar/Sites/_library/Doctrine-0.11.1/Doctrine/Access.php(133): Doctrine_Record->set('team', Object(Team))
        #3 /Users/ishtanzar/Sites/_library/Doctrine-0.11.1/Doctrine/Hydrator.php(225): Doctrine_Access->offsetSet('team', Object(Team))
        #4 /Users/ishtanzar/Sites/_library/Doctrine-0.11.1/Doctrine/Query/Abstract.php(999): Doctrine_Hydrator->hydrateResultSet(Object(PDOStatement), Array)
        #5 /Users/ishtanzar/Sites/test/testDoctrineRelations/index.php(16): Doctrine_Query_Abstract->execute()
        #6 {main}
          thrown in /Users/ishtanzar/Sites/_library/Doctrine-0.11.1/Doctrine/Record.php on line 813

From romanb :

all column names (not aliases) are forced to lowercase in doctrine for portability. That is, if you do: hasColumn('team_teamId as id') doctrine stores: column name = team_teamid , column alias (field name) = id. And it looks like the relation mapping does not force the given name to lowercase before looking it up, maybe it should.

Attachments

Episode.php (0.9 KB) - added by ishtanzar 11 months ago.
Team.php (0.9 KB) - added by ishtanzar 11 months ago.

Change History

Changed 11 months ago by ishtanzar

Changed 11 months ago by ishtanzar

Changed 10 months ago by jwage

  • version changed from 0.11 to 1.0
  • milestone changed from Unknown to 1.0.0-RC2

Changed 10 months ago by anonymous

  • milestone New deleted

Milestone New deleted

Changed 10 months ago by jwage

  • milestone set to 1.0.3

Changed 9 months ago by romanb

  • status changed from new to assigned

Changed 9 months ago by jwage

  • milestone changed from 1.0.3 to 1.0.4

Changed 9 months ago by jwage

(In [5092]) [1.0, 1.1] addresses #1341 Added test coverage

Changed 9 months ago by jwage

(In [5093]) [1.0, 1.1] addresses #1341 fixed test so it fails

Changed 9 months ago by jwage

(In [5094]) [1.0, 1.1] addresses #1341 updated test again to fail differently.

Changed 9 months ago by jwage

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

(In [5095]) [1.0, 1.1] fixes #1341 - issue with local/foreign and column aliases

Changed 9 months ago by jwage

The local/foreign should be the alias. The SQL now generated will now make sure it generates the column name and not the field name. The problem was that if you specify the column name, it will try and update the object with that column name and throw an exception. It will also error if you specify the field name because it would try and include that field name in the generated sql. So, now we just need to make sure that in all places where sql is generated, the local and foreign are converted to the column name.

Note: See TracTickets for help on using tickets.