The only way currently to force a join is to run  
thinking_sphinx:configure, then edit the generated SQL, then run
rake thinking_sphinx:index INDEX_ONLY=true

I know it's not elegant, but it's the best solution at the moment.

Cheers

-- 
Pat

On 13/12/2008, at 9:19 PM, Shumkov wrote:

>
> Its does not work, becouse posts not owned projects in database.
> Posts aleady have attribute from owner (has owner.city_id, :as
> => :city_id).
>
> How i'm can force join or maybe add sql condition in where (but as i'm
> known it's imposible)?
>
> On 13 дек, 10:01, Pat Allan <[email protected]> wrote:
>> To force joins to all the polymorphic tables, you'll need to add a
>> field or - probably better - an attribute that uses a common field
>> across all the appropriate models. The best choice is, of course, id.
>>
>> So:
>>
>> has owner(:id), :as => :owner_id
>>
>> And then both clubs and projects should be included in the SQL
>> statement *IF* there are posts owned by projects in the database.
>> Thinking Sphinx can't figure out by itself which models are
>> appropriate for polymorphic joins, so it looks at the existing data.
>> If there's no data joining posts to clubs or projects, then they  
>> won't
>> have the needed joins. I know it's not an ideal situation, but I
>> haven't found a better way yet.
>>
>> --
>> Pat
>>
>> On 12/12/2008, at 10:01 PM, Shumkov wrote:
>>
>>
>>
>>> Hello, i have some problem with index conditions.
>>> I'm have Post model with polymorphic relationship with Club model  
>>> and
>>> Project model. And i can't index posts if club or project is not
>>> active.
>>
>>> Look this:
>>
>>> class Post < ActiveRecord::Base
>>
>>>  belongs_to :owner, :polymorphic => true
>>
>>>  define_index do
>>>    indexes title, cached_tag_list
>>>    indexes body, :html_strip => true
>>
>>>    has owner.city_id, :as => :city_id
>>
>>>    where "(`clubs`.activated_at IS NOT NULL OR
>>> `projects`.activated_at IS NOT NULL)"
>>
>>>    set_property :match_mode => :boolean
>>>    set_property :delta => true
>>>  end
>>
>>> end
>>
>>> class Club < ActiveRecord::Base
>>>  has_many :posts, :as => :owner
>>> end
>>
>>> class Project < ActiveRecord::Base
>>>  has_many :posts, :as => :owner
>>> end
>>
>>> If i'm have projects and clubs and posts index sql query is good!  
>>> But
>>> if i'm don't have Project for example in index sql query join with
>>> table projects is not present. And i'm have error on indexing:
>>
>>> ERROR: index 'post_core': sql_range_query: Unknown column
>>> 'projects.activated_at' in 'where clause' (DSN=mysql://
>>> root:*...@localhost:3306/clubovorot).
>>
>>> What can i do?
> >


--~--~---------~--~----~------------~-------~--~----~
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