Planned to still support Active Record in Yii 2.0?

Hi there!

Are you planning to still support the Active Record pattern for persistence in Yii 2.0?

I guess that it is a very important thing in what should be sought for the next version of Yii, I say this because I don’t guess that the Active Record is NOT the very correct pattern to implement in an Object Oriented design.

The causes are multiple…

  • The domain/business model is "dirtied" by the persistence logic.

  • With this "Relational Object Mapping" there are more possibilities to fall in an anemic business model.

  • We stilling view our model as a relational model and not an object model.

  • On many occasions the Yii user must think in terms of database queries to persist the model, inside the model!

The thing is that is really easy see a class as a simple table and an object as a simple record, but because the impedance of realational model and object model paradigms, this approach rarely falls on a good model design.

Is what I have seen using the Active Record pattern and a less intrusive model persistence method, It seems true that the choice between one or another design pattern is sometimes subjective.

Did you considered another way to persist the model instead of Active Record on Yii 1.x develop?

Do you consider for the development of Yii 2.0 (for example, Doctrine 2 or another non-intrusive ORM)?

What is your opinion about benefits and cons in persistent pattern/s choice?


Yii is build for speed and flexibility. It’s not accidental that Yii exposes the DAO - in real world you need to go to the SQL level to do things fast, efficient and resource friendly. ORM is a DB abstraction layer - theoretically it’s good. Practically - bullshit. It works fine until you do not use any DB specific features. And if you build something to work under the real load (and works in the wild) - you must use those specifics and you have to go down to the SQL level in any case. Consider queries with derived tables - very other is a perfect way how to optimize a query. Or MySQL’s IN operator, witch isn’t a standard SQL as I know.

ORM’s for PHP are just too heavy and bulky. For the most projects it’s an overkill and AR works just fine. Consider deepening your knowledge about Yii’s AR - you will be surprised how well it’s designed and allows you to do just tons of stuff.

One of the greatest strengths of Yii is its sophisticated Active Record implementation. It shouldn’t be dropped just because Martin Fowler prefers Data Mapper :)

Active Record works perfectly well for simpler applications - and this simpler applications constitute 99% of the Web. I’m aware of the limitations of Active Record and possible advantages of a Data Mapper/ORM in some circumstances, but I can use Doctrine2 with any Yii app, if needed. And with this new extension it will be even easier.

I think the AR support on Yii 2.0 Must stay, Im waiting a Yii 2.0 with Yii 1.X apps compatibility.

Anyway, I think we need more effort for support Doctrine2 like a Extention. To this time, i see the Doctrine2ORM without change… But i have Hope :)