#55 ✓resolved
kgiszczak

:select option doesn't work

Reported by kgiszczak | February 23rd, 2009 @ 08:30 AM

When declaring association with :select option, searchlogic ignore this option. For example:


  class User < ActiveRecord::Base
    has_many :posts, :select => 'whatever'
  end

  controller:

  def index
    @search = current_user.posts
    @posts = @search.all
  end

Generated query is: SELECT * FROM posts

Searchlogic version: 1.6.4

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson March 6th, 2009 @ 05:54 AM

    • State changed from “new” to “resolved”

    Searchlogic just uses the scope passed to it. I believe ActiveRecord is the one ignoring the select, because I don't hand pick options from associations. If you dig into how AR handles associations you will see it essentially sets up a scope. I don't think there is anything I can do about this, sorry.

  • Ben Johnson

    Ben Johnson March 6th, 2009 @ 05:55 AM

    To prove my point, check out the "construct_scope" method in the HasManyAssociation class:

    def construct_scope
              create_scoping = {}
              set_belongs_to_association_for(create_scoping)
              {
                :find => { :conditions => @finder_sql, :readonly => false, :order => @reflection.options[:order], :limit => @reflection.options[:limit], :include => @reflection.options[:include]},
                :create => create_scoping
              }
            end
    
  • preszke

    preszke March 9th, 2009 @ 05:40 AM

    Hi,

    Instead of trying @posts = @search.all

    try @posts = @search.find(:all)

    It should work as 'all' is alias method for find(:all) only in the ActiveRecord::Base, and find(*all) is defined directly in the AssociationCollection.

    While it tries to find the 'all' method in the method missing blocks it loses some of the information about scope.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Provides common named scopes and object based searching.

People watching this ticket

Pages