[英]How to insert value of subquery using Active Record?
我使用活動記錄將值插入數據庫。
所有其他類型的查詢我都使用自定義查詢,因為它更容易,但活動記錄插入非常好。
所以我有這個代碼:
$comment = array (
'point_id' => $object->id,
'title' => $object->title,
'comment' => $object->comment,
'author_name' => $object->author_name,
'is_temp' => 0,
'parent_id' => $object->parent_id
);
return $this->db->insert('comments', $comment);
現在我希望能夠將 is_temp 設置為子查詢結果,即:
(SELECT allow_user_comments from subjects where id='somevalue')
如何做到這一點?
我希望避免使用第三方庫。
好吧,我懷疑這就是你應該這樣做的事實,但 CI 不就是這樣嗎?
這就是我讓它工作的方式(當然從 $comment 數組中刪除 is_temp ):
$this->db->set($comment);
$this->db->set('is_temp',
'(SELECT allow_user_comments from subjects where id='.$subject_id.')',FALSE);
$this->db->insert('comments');
隨意使用https://github.com/NTICompass/CodeIgniter-Subqueries 。 我已經使用過它並且有效! 希望它會很有用。 :-)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.