2010-04-05 56 views
2

我已經從一些路段排除從結果有些IDS在Rails的ActiveRecord的

Article.all(:joins => :sections, :conditions => { :sections =>{ :id => [3, 4, 6, 7, 8, 9] }, :id_not_in => @some_ids }, :limit => 4) 

可變@some_ids以下爲文章的查詢語句是陣列的文章至極必須從結果中排除的ID。

+0

你的問題是正好? – vladr 2010-04-05 20:33:56

+0

文章和版塊之間有什麼關係? – 2010-04-05 20:52:50

回答

9

如果Articlehas_many :sections,嘗試:

Article.find(:all, :joins => :sections, :conditions => ["sections.id IN (?) AND 
    id NOT IN (?)", [1,2,3], @some_ids], :limit => 4) 
2
Article.all(:joins => :sections, 
    :conditions => [ 'sections.id in ? and sections.id not in ?', 
    [3, 4, 6, 7, 8, 9], @some_ids ], :limit => 4) 

未經檢驗