tags:

views:

55

answers:

1

I've just started working with Doctrine and I don't quite understand the purpose of table classes and base classes. What is the benefit of generating them explicitly? Is any change necessary in the application logic when these classes are pre-generated and when they are not?

Could you clarify this topic a bit? Thanks.

A: 

As far as I know, using doctrine generated classes is no different to using models you've written from scratch. I would say the main benefit of generating them automatically is that (apart from involving less work for you!) it cuts down the risk of errors like typos etc. I tend to think of base classes as the place where basic structure and relationships are contained. I then put any table specific functions in the table class. Don't forget that all the table classes inherit from their base class and so you only ever need to refer to the table class explicitly.

musoNic80
I agree with a lot of what is said here, but I disagree with adding your own relationships at the base classes. Adding hasMany/hasOne relationships in the Base class setUP seems right, but if the database is changed and generateModelsFromDb is run again, all custom code in the base class is blown away. Instead, build your relationships in the explicit class' setUp function to avoid lost code.
shambleh
Very good point. I think this highlights the difference between an ideal situation and a real world situation.
musoNic80