开发者

Why isn't ActiveRecord a module?

To get all the ActiveRecord goodies your class must inherit from ActiveRecord::Base:

class Post < ActiveRecord::Base

Why not ask the user to include ActiveRecord as a module instead?

The advantage of this approach is that Rails could automatically include ActiveRecord in all classes in the models directory, making it completely transparent to the use开发者_开发问答r. I.e.:

class Post # no `< ActiveRecord::Base`!

Is this a (relatively minor) design flaw in Rails?


ActiveRecord is not Hibernate. ActiveRecord models are not pure models - they are explicit Active Records and follow the semantics of the Active Record pattern.

This is not a design flaw. This is a completely different design goal.

I would certainly like to see a Ruby Hibernate. But ActiveRecord is not it.

Martin Fowler describes an Active Record as:

An object that wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜