Hmm, that's annoying - I've got a test case that covers this exact scenario 
(array with a symbol and hash), and it passes. Good to know you've found a way 
to work around the issue though.

-- 
Pat

On 04/04/2011, at 4:20 PM, ayoo wrote:

> Yes, [:city, {:franchise => :menus}] works in normal active record
> call.  I remember doing it in rails 2.3 and I verified in rails
> 3.0.5.  (For the sake of simplicity, I what I called franchise in my
> example is actually called :chain in my app.  I thought calling it
> franchise would make more sense to any help.)
> 
> ruby-1.9.2-p136 :006 >   Restaurant.where(:id=> 3).includes([:city,
> {:chain => :menus}])
>  Restaurant Load (57.4ms)  SELECT `restaurants`.* FROM `restaurants`
> WHERE `restaurants`.`id` = 3
>  City Load (18.8ms)  SELECT `cities`.* FROM `cities` WHERE
> (`cities`.`id` = 2)
>  Chain Load (13.3ms)  SELECT `chains`.* FROM `chains` WHERE
> (`chains`.`id` = 202)
>  Menu Load (117.6ms)  SELECT `menus`.* FROM `menus` WHERE
> (`menus`.chain_id = 202 AND (menus.deleted_at is null)) ORDER BY
> position asc
> => [#<Restaurant id: 3, chain_id: 202, city_id: 2, phone:
> "4152921888", fax: nil, address: "3348 Steiner St", slug:
> "3348steinerst", lat: #<BigDecimal:105aec698,'0.37800381E2',18(18)>,
> lng: #<BigDecimal:105aec5a8,'-0.122437548E3',18(18)>, published_at:
> "2011-03-20 06:53:53", created_at: "2011-03-20 06:16:38", updated_at:
> "2011-03-20 06:53:53", deleted_at: nil, zipcode: nil, rating_average:
> #<BigDecimal:105aeb338,'0.0',9(18)>, delta: false>]
> 
> I figured a work around by directly associating menus to my restaurant
> model.
> has_many :menus, :class_name => 'Menu', :primary_key
> => :chain_id, :foreign_key => :chain_id
> 
> This allows me to do the include directly with [:city, :chain, :menus]
> instead of trying to go through the :chain model to access the menus.
> I hope this helps someone out there.
> 
> -Andrew
> 
> 
> 
> On Apr 1, 9:43 pm, Pat Allan <[email protected]> wrote:
>> Should [:city, {:franchise => :menus}] work in a normal Rails query?
>> 
>> --
>> Pat
>> 
>> On 27/03/2011, at 9:29 PM, ayoo wrote:
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>> Sorry I didn't realize I got a response.
>> 
>>> Anyway, I'm using thinking_sphinx v2.0.0 on rails 3.  I just tried
>>> the :include => {:franchise => :menus} (without the array) and it now
>>> eagar loads the francise and the menus!  However there is still an
>>> issue.  In my app I am trying to eagar load another association as
>>> well.
>> 
>>> When i try include => [:franchise, :city], it manages to eager load
>>> the 2 associations.  When i do :include => {:franchise => :menus}, it
>>> eagar loads the franchise and the menus.  Is there a way for me to
>>> eagar load all three associations?  I've tried include => [:city,
>>> {:franchise => :menus}], but it doesn't suppose this.
>> 
>>> On Mar 23, 1:42 pm, Pat Allan <[email protected]> wrote:
>>>> Heya
>> 
>>>> Firstly - what version of Thinking Sphinx are you using? Also, what 
>>>> happens if you try :include => {:franchise => :menus} - removing the 
>>>> surrounding array?
>> 
>>>> --
>>>> Pat
>> 
>>>> On 23/03/2011, at 1:13 PM, ayoo wrote:
>> 
>>>>> Hi everybody and especially Pat.
>> 
>>>>> I have the following models:
>> 
>>>>> class Restaurant < ActiveRecord::Base
>>>>>  belongs_to :franchise
>>>>>  define_index...
>>>>> end
>>>>> class Franchise < ActiveRecord::Base
>>>>>  has_many :restaurants
>>>>>  has_many :menus
>>>>> end
>>>>> class Menu < ActiveRecord::Base
>>>>>  belongs_to :franchise
>>>>> end
>> 
>>>>> And i setup the sphinx index on my restaurant model.  When i search:
>>>>> Restaurant.search('food', :include => [:franchise])
>>>>> chains are eager loaded as expected.
>> 
>>>>> But is there a way to eager load menus as well?  I tried the normal
>>>>> rails convention of eager loading nested associations, but that didn't
>>>>> work
>>>>> Doesnt Work ## Restaurant.search('food', :include => [ { :franchise
>>>>> => :menus }])
>> 
>>>>> Can it be done and how? Thanks!
>> 
>>>>> --
>>>>> You received this message because you are subscribed to the Google Groups 
>>>>> "Thinking Sphinx" group.
>>>>> To post to this group, send email to [email protected].
>>>>> To unsubscribe from this group, send email to 
>>>>> [email protected].
>>>>> For more options, visit this group 
>>>>> athttp://groups.google.com/group/thinking-sphinx?hl=en.
>> 
>>> --
>>> You received this message because you are subscribed to the Google Groups 
>>> "Thinking Sphinx" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to 
>>> [email protected].
>>> For more options, visit this group 
>>> athttp://groups.google.com/group/thinking-sphinx?hl=en.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/thinking-sphinx?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to