2

I get number of problems trying to implement CTI

First of all I use a custom loader for my entity classes

class My_AutoLoader implements Zend_Loader_Autoloader_Interface
{

    public function autoload($class)
    {
        $class = trim(str_replace('\\', '/', $class), '/');
        if (@include(APPLICATION_PATH . '/Entities/' . $class . '.php')) {
            return $class;
        } else {
            throw new Zend_Loader_Exception('Cannot load ' . $class . '.');
        }
    }

}

The idea is to use application\Entities for classes that have no namespace like $user = new Users();

Then I have defined class inheritance

Profiles:
  type: entity
  table: profiles
  repositoryClass: Repositories\Base
  inheritanceType: JOINED
  discriminatorColumn:
    name: profiletype
    type: integer
    length: 11
  discriminatorMap:
    1: Personal
    2: Work
    3: Business
  id:
    id:
      type: integer
      generator:
        strategy: AUTO
  fields:
    firstname:
      type: string
      length: 255
      fixed: false
      nullable: true
    ...


Work:
  type: entity
  table: work
  repositoryClass: Repositories\Base
  fields:
    position:
      type: string
      length: 255
      fixed: false
      nullable: true

then I have manually created the class Work to extend Profiles

class Work extends Profiles
{
}

The first problem begun with 2.0.0 (2.0.1), when I use console tool's generate-entities I get the error that I don't have id's for the Work class, it is odd because IMHO it contradicts with the idea that Work extends Profiles and id is already defined.

However I tried to add a column id for the Work class, but then I get a message that I already have a column id. DOH!

I tried to add some other column name for PK but I actually get an extra column that is unnecessary because the proper inherited column id is also created. In CTI i should have a single FK column and there are no other PK's with auto-generated values.

So I did the bad thing to hack the doctrine classes and remove the checks for missing id's. Ugly but it worked. The entities start to generate properly and the db structure is just fine.

I later found that all that strange behavior is due to a bug in doctrine 2 and it is fixed in 2.0.5.

Well, I tried 2.0.5 and had exactly the same problem, so I thought the mistake is in my code.

I filed a bug in doctrine's jira and I got answered that my definitions are wrong and I need id's for subclasses (and got referred to the documentation that all we know is quite poor, especially for YAML mapping). I gave up and sticked with my hack.

Later I tried with 2.0.6 and 2.1 but with those versions my entities are no longer updated but each time i use generate-entities the new class definitions are being append to the end so there are duplicates.

My question is:

Is this a problem with doctrine or I am doing it wrong?

If it is in me what is the proper way of mapping CI

genesis
  • 50,477
  • 20
  • 96
  • 125
venimus
  • 5,907
  • 2
  • 28
  • 38
  • 1
    I have successfully used CTI from 2.0.4 to 2.1 with annotations. Entity subclasses don't need ID field, you can be sure of that. A FK/PK id field is nonetheless automatically created by Doctrine in the subclasses DB tables. Try creating your schemas programatically following these instructions: http://www.doctrine-project.org/docs/orm/2.0/en/reference/tools.html#database-schema-generation . I can post my own code if you think it helps (but its with annotations, not yaml). – faken Jun 28 '11 at 01:06
  • actually I often used the annotations for reference to make the more complex definitions, but seems I'm doing it the proper way, probably the bug is in generate-entities and probably confused by my autoloader which the only odd thing I'm using (that is why I also provided it). Btw the db schema is created just fine if I fix my entities (remove the duplicates). – venimus Jun 28 '11 at 08:32

1 Answers1

0

Taken from your question:

Update: I found that the problem is actually a bug in Doctrine which always prefix the namespace with "\" when updating entities and my custom autoloader loads only classes without namespace. In addition there is a bug with inheriting properties (ids)

Both will be fixed in 2.1.1

genesis
  • 50,477
  • 20
  • 96
  • 125