Following were my query in controller:
@cref = Creference.where("lower(name) LIKE ?", "#{@city.downcase}")
if @cref.present?
cities_array = @cref.map {|con| "%#{con.countries}%" }
#cities_array return --> ["%["Kuching", "Kota Kinabalu"]%"]
@products.where("city ILIKE ANY ( array[?] )", cities_array) --> []
end
The product doesn't return any result despite there is city with above name in Product table. Thanks!!
SCHEMA
product:
create_table "products", force: :cascade do |t|
t.integer "user_id"
t.string "name"
t.integer "payment_type", limit: 2
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "product_category_id"
t.integer "location_id"
t.text "description"
t.text "highlight"
t.integer "price_cents"
t.integer "zip"
t.string "country"
t.string "state"
t.string "city"
t.string "address"
t.string "apt"
t.integer "refund_day"
t.string "currency"
t.integer "refund_percent"
t.integer "refundable", limit: 2, default: 0
t.integer "step", limit: 2, default: 0
t.integer "discount", default: 0
t.string "slug"
t.integer "status", limit: 2, default: 1
t.integer "verification", limit: 2, default: 0
end
creference:
create_table "creferences", force: :cascade do |t|
t.string "name"
t.string "countries", default: [], array: true
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
@productsis empty or nil tryProduct.where("city ILIKE ANY ( array[?] )", cities_array) --> []it should return products if matched any.schemafor Creference and Product model?