CodeIgniter Forums
Is this really ActiveRecord? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Is this really ActiveRecord? (/showthread.php?tid=11555)



Is this really ActiveRecord? - El Forum - 09-13-2008

[eluser]7bit[/eluser]
Hello,

I'm new to CI and am in the process of exploring the possibilities of the framework. So far I looks very nice to me. But I have a question regarding the ORM:

In the manual it says you should derive your domain objects from the class Model. It also says it is using some kind of ActiveRecord, but looking inside the declaration of the Model class i can't see any reference to any built in ActiveRecord functionality. I would have expected that I just can declare a class Foo that would extend Model, declare just a few variables to tell the model about its relationships to other tables and then it would automatically have all needed functionality to represent fully working 'foo' objects transparently connected to the 'foo' table, able to load, update, save and pull in other objects that represent data in related tables and so on. Instead the manual states that I have to manually declare functions like find_foo(), find_bar(), save(), do_whatever() and inside all this manually written functions i have to manually call almost naked db driver functions like $this->db->get(), $this->db->insert(), $this->db->update(), $this->db->foobar() over and over again. This doesn't look like anything near ActiveRecord at all.

(?)

Did I completely misunderstand something here? I know that there are many 3rd party ORM modules for CI but i would like to understand the concept behind CIs "ActiveRecord" and maybe an example how to use it correctly so that it really looks and feels like all the other ActiveRecord implementations I have seen. I haven't found much documentation about this subject.

TIA,
Bernd


Is this really ActiveRecord? - El Forum - 09-13-2008

[eluser]garymardell[/eluser]
Quote:regarding the ORM:

Im afraid there is no ORM with codeigniter. The active record just refers the process of using functions to create queries in CI without writing SQL.


Is this really ActiveRecord? - El Forum - 09-13-2008

[eluser]Pascal Kriete[/eluser]
It certainly isn't ORM, and never claims to be. It isn't really ActiveRecord, either. According to the manual it's a modified version.
Quote:CodeIgniter uses a modified version of the Active Record Database Pattern.

In all reality it's probably best described as a database adaptor.

A little note on the difference between ORM and AR:
ORM often uses an ActiveRecord pattern, but the reverse isn't true. The difference is basically that AR does not have to handle relationships, it usually just describes them. So pure AR is: Blog.delete() ... Comments.delete(). ORM will automatically cascade.


Is this really ActiveRecord? - El Forum - 09-13-2008

[eluser]dimis[/eluser]
Is it a good idea to use an orm as Doctrine with CI?
Has someone did it?


Is this really ActiveRecord? - El Forum - 09-13-2008

[eluser]Colin Williams[/eluser]
I've always gotten by without an ORM library (doesn't mean I don't do ORM, I just don't farm it out to a monolithic ORM library). It's a good idea if you particularly like or for some reason require a single ORM API. Search the wiki for "Doctrine" It's been done.


Is this really ActiveRecord? - El Forum - 09-14-2008

[eluser]m4rw3r[/eluser]
There are also a few CI specific ORM libraries which utilize CI's underlying DB abstraction (my own included), search here on the forums for ORM.
They may not be as complete as Doctrine though, but what you should use depends on your needs.