开发者

Using Active Record on object split across two tables in codeigniter

I have a controller that is represented in the database by two tabl开发者_Python百科es, 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?


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜