问题
I have a mysql database table called UserDegree, when i try to import back to PHP using Doctrine it generates a model name Userdegree, is there a way to solve this?
i really can't find any good doctrine documentation.
thanks!
回答1:
I am not sure about your specific problem, but for the "good doctrine documentation" part, did you try the manual ? See Doctrine ORM for PHP -- I think it's actually quite good, especially compared to what you get with some other projects, that don't have much documentation, or totally outdated.
About your problem (as I said before, not sure) : I suppose Doctrine takes each "word" from the table name in the DB, and converts that to a "name" for PHP. Quite often, "words" in table names are separated by an underscore '_
', and are all in either lower or either case.
I suppose, if you name your table "user_degree
", instead of "UserDegree
", that Doctrine should detect it's composed of two "words", and create a PHP class called "UserDegree
" -- actually, I tested with a table called post_has_tag
, and it generates a class called PostHasTag
.
回答2:
Pascal Martin is correct. The table should be named like user_degree, in this case Doctrine will generate UserDegree class.
I also recently figured out that it is possible to keep all database identifiers to be under_scores, while having Doctrine to generate camelCase'd code. It happens automatically for table names, as said above. As for field names, they can be mapped to camelCase using alias feature of YAML schema file (name: user_id as userId). Moreover, you can automate field aliasing by developing custom task for Doctrine.
来源:https://stackoverflow.com/questions/1501501/doctrine-orm-models-not-respecting-case