我已經在Codeigniter中介紹了activerecord和手動查詢。當所有關於標準查詢並且開發時間非常短的時候,ActiveRecord都非常棒。Codeigniter:結合activeRecord和手動查詢?
但是,當需要爲查詢添加一些複雜性時,ActiveRecord會變得非常複雜。子查詢或複雜的聯接給了我很多頭痛。
由於當前「$ this-> db-> query」調用立即執行設置的查詢,因此它不能與正常的activeRecord調用結合使用。
那麼,我能做些什麼來結合這兩種方法呢?什麼我要完成
例子:
$this->db->select('title, content, date');
$this->db->from('mytable');
$this->db->manual('UNION'); // My own idea of db-call that appends UNION to the query
$this->db->select('title, content, date');
$this->db->from('mytable2');
$query = $this->db->get();
謝謝!
我們展示了一個複雜的查詢的聯合國例子,也許我們可以想想,我們如何能夠用做ActiveRecord的。 AFAIK你不能結合$ this-> db-> query()+ $ this-> db-> get(),如果這是你的意思。 – Bogdan 2010-06-06 18:40:42
嗨,這實際上是我一直在想的事情,所以我恐怕現在我沒有一個具體的例子。正如你所說,我知道$ this-> db-> query()+ $ this-> db-> get()不能合併:) – Industrial 2010-06-06 18:43:21
我與Bogdan,一個示例查詢會很好。 – DRL 2010-06-07 10:04:10