views:

27

answers:

1

I have a controller that is represented in the database by two tables, pages and page_contents. pages contains the author information, unique id for the the page, and creation timestamp. page_contents contains the page uid as a FK, the contents of the page, last editor, and edit timestamp.

When a page it requested I need to pull the original author and creation timestamp, the contents of the most recent revision of the page contents.

How would I do this using active record methods? Or will I have to use $this->db->query(() and a handcrafted SQL statement?

A: 

You can use the join ($this->db->join();) methods provided by the active record library to specify how to connect the two tables but if you're looking for more ORM style retrieval try the Doctrine Library for Codeigniter I'm not 100% sure if it will support it but it's what frameworks like symfony use to get this behavior.

The new version of Codeigniter (2.0) will include a more ORM style model retrieval. ORM is one of the big reasons for Kohana (a fork of Codeigniter) that actually includes try active record.

Ken Struys
An alternative to Doctrine is the Datamapper Overzealous library created for Codeigniter - http://www.overzealous.com/dmz/
someoneinomaha
@someoneinomaha have you had any experience with it? what's your opinion?
Ken Struys
I've been using it on a project that I've been working on (on off hours) for about a year now. I really like it for the most part. There are a few things that seem odd - if you view the profiler, you'll see it do a select @ from table limit 1 whenever you instantiate a new object... but if you turn caching on, it no longer has to do that.
someoneinomaha