Empty result when multiple select. HABTM + Ransack #187

Open
dl33ter opened this Issue Jan 15, 2013 · 0 comments

Comments

Projects
None yet
1 participant

dl33ter commented Jan 15, 2013

I have a form with :

    <%= f.collection_select :carburants_id_eq_all, Carburant.order(:name), :id, :name, {}, { multiple: true } %>

When I select only 1 Carburant, it's render me the result normaly, but if I select more than 1 Carburant, the result is empty.

Here's my form in 'index.html.erb' :

    <%= search_form_for @search do |f| %>

<%= f.label :title_cont, "Name contains" %>
<%= f.text_field :title_cont %>

 <%= f.collection_select :carburants_id_eq_all, Carburant.order(:name), :id, :name, {}, { multiple: true } %>

    <%= f.submit "Search" %>
    <% end %>

My index action in my 'post_controller.rb':

      def index
         @search = Post.search(params[:q])
        @posts = @search.result(distinct: true)
      end

My post.rb, carburant.rb and category.rb model :

     class Category < ActiveRecord::Base
     attr_accessible :carburant_id, :post_id
     belongs_to :carburant
     belongs_to :post
     end

     class Post < ActiveRecord::Base
     attr_accessible :content, :title, :carburant_ids
     has_many :categories
     has_many :carburants, through: :categories 
     end

     class Carburant < ActiveRecord::Base
     attr_accessible :name
     has_many :categories
     has_many :posts, through: :categories
     end

My DB shema :

     ActiveRecord::Schema.define(:version => 20130114004613) do

        create_table "carburants", :force => true do |t|
        t.string   "name",       :limit => nil
        t.datetime "created_at"
        t.datetime "updated_at"
       end

      create_table "categories", :force => true do |t|
      t.integer  "post_id"
      t.integer  "carburant_id"
      t.datetime "created_at",   :null => false
      t.datetime "updated_at",   :null => false
      end

     create_table "posts", :force => true do |t|
     t.string   "title"
     t.text     "content"
     t.datetime "created_at"
     t.datetime "updated_at"
    end

    create_table "recherches", :force => true do |t|
    t.string   "title"
    t.integer  "carburant_id"
    t.datetime "created_at",   :null => false
    t.datetime "updated_at",   :null => false
   end

   end

Thank you by advance.

EDIT 1:

I tried replacing :carburants_id_eq_all by :carburants_id_eq_any in my form just to test, and it work perfecly with the EQ_ANY predicate, but still not with the EQ_ALL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment