2016-03-28 20 views
0

Üç Kayıtlı and koşulu (iki) ve iki or koşuluyla Aktif Kayıt yazmak istiyorum.Aktif Kayıt, "ve" ve "veya" koşullarında Ruby'de nasıl yazılır

@properties = Property.where(category_id: 2). 
         where(status: 3). 
         where(p_type: 'sell')` 

Bu and koşullarla sorgu listelenmektedir:

ben yazdım.

Sonunda iki adet or koşulunu eklemem gerekiyor.

Bu çalıştı ama bir hata var: Bunu nasıl yapacağım

@properties = Property.where(category_id: 2). 
         where(status: 3). 
         where(p_type: 'sell'). 
         or(location: @location). 
         or(featured: '1)` 

?

+2

bu '@properties = Property.where (category_id: 2, statü: 3) deneyebilirsiniz .Where ("??? (P_type = VEYA konum = VEYA özellikli =)", 'sat', @ konum, '1') ' –

+0

Teşekkür ederim. Bu kod çalışıyor :) – SreRoR

+2

'nerede(). or()' yöntem zinciri Raylar 5'te mevcut olacaktır. [buraya] eklenmiştir (https://github.com/rails/rails/pull/16052/) . – Drenmi

cevap

0

Bunu deneyebilirsiniz.

@properties = Property.where(category_id: 2, status: 3).where("(p_type = ? OR location = ? OR featured = ?)", 'sell', @location, '1') 
1
@properties=Property.where("(category_id = ? AND status = ?) OR (location = ? OR featured = ?)", "2", "3", @location, "1") 
+0

Bu kod ayrıca çalışır, teşekkürler @Muhammad – SreRoR

İlgili konular