开发者

Is CodeIgniter's Active Record class just a database abstraction layer?

It seems as though CodeIgniter's active record class is 开发者_运维知识库just a DAL. How is it qualified as an active record pattern?


A lot of people that I've talked to and even the codeigniter forums point to the fact that they accept that it's not actually the traditional Active record pattern most of us are used to such as in Ruby on Rails. On the other hand, there are also others that state that there are many different ways of expressing the Active Record pattern, as it is technically creating objects with fields that correspond to database tables.

But it is indeed lacking the actual save and delete. But I also think it can also be argued that it very easily has the functionality of an active record if you just get a little creative with the database object and pass it to an class that can represent actual active records as we know them. I think it lays a pretty solid foundation for easily implementing something that looks and acts very traditional active record.

aaand, for the other essential parts of what I know of the usefulness of Active Record, for a model that is supposed to represent an object from a certain table...

Create: $db->insert($this);

Read: $db->get($this->table_name,$this->id); ... or something of the sort.

Save: $db->update($this);

Delete: $db->delete($this->id);

Of course, it's lacking a lot of the automaticness of the features of CakePHP and such, but at the same time it is heavily laying the foundation for at least a basic active record class, and you'll probably want to use a factory to pass the $db into the objects so that when you call "save" it doesn't add a bunch of non-essential information... but... I'm going to stop here because I think I'm taking things a little too far :).

I just wish it had better capabilities for when you joined different tables.

In conclusion, it really just seems that Codeigniter is 60% traditional active record, while it's mostly just an abstraction thrown on top of basic sql statements.


The ActiveRecord pattern is a data access layer implementation just as Data Mapper is. The data access layer can be written in many ways.

Data Mapper Pattern

Active Record Pattern

Data Access Layer

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜