我必須稱爲DraftPost
和PublishedPost
相同的模型。我試圖做的是從特定網站上查找稿子和發佈的帖子,然後將它們合併在一起。合併ActiveRecord對象和他們的孩子在一起
draft_posts = DraftPost.where(:site_id => params[:site_id]).includes(:comments)
#=> 3 draft posts
published_posts = PublishedPost.where(:site_id => params[:site_id]).includes(:comments)
#=> 2 published posts
# here I want to merge the draft_posts to the published_posts. e.g;
published_posts.merge(draft_posts)
#=> here the result should be 3 published posts (update the existing two and create one new)
你會如何做到這一點?謝謝。
您是否嘗試過draft_post + published_post? – qcam
您應該使用STI而不是創建兩個表格。 – Hauleth
@hauleth:tnx,它是一個已經存在的項目,我需要繼續這個工作..現在不能改變它。 – tokhi