Ticket #706 (closed defect: invalid)

Opened 2 years ago

Last modified 2 years ago

(Attn: Jonwage) generateModelsFromDb issues

Reported by: EGreg Owned by: JonWage
Priority: major Milestone: 2.0.0 (OLD)
Component: Other Version:
Severity: Keywords:
Cc: Has Test:
Status: Has Patch:

Description

Okay, disclaimer: I just started learning Doctrine yesterday. I took the DB I already had and called

Doctrine::generateModelsFromDb(my_model_dir($dbName));

Two issues: 1) Request: It did not generate the relations between tables. I have to add these in by hand. I realize this may take some work to add in.

2) Bug: It generated classes which it put in the dir I specified, and it also created a "generated" folder inside, which contains the generated code. That's all good, so I can extend the classes and not have my code overwritten by the generator. But! Then this structure isn't recognized by the autoloader currently. When I called loadModels

Doctrine::loadModels(faf_doctrine_model_dir($dbName), true);

I expected the autoloader to find my classes, such as $user = new User(); It does. But it's funny to see a fatal error saying "BaseUser? not defined." Please make the autoloader work with the structure of the autogenerator. Currently I have to include these things manually.

I think these improvements will really help boost Doctrine's popularity. People come to doctrine FROM some kind of previous setup, and they usually have a database already. It would be nice to autogenerate code from that database without manually retyping the relations, etc. Currently there is a barrier to adoption because of all this menial work that has to be done by the user of Doctrine.

Change History

Changed 2 years ago by jwage

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

Which version of Doctrine are you using?

In trunk you have to change the model loading to be conservative:

Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);

By default the model loading is aggressive and it will attempt to require every single php file that is found at the given path. With conservative, it finds all php files and builds an array of className => path where the className is the name of the file minus the extension. This array is then referenced in autoload() when a class/model is asked for. This requires that each file can only have one model in it, and the file must be named after the model.

Note: See TracTickets for help on using tickets.