Hi Thibaut
Personally, I'd be getting this information out via normal SQL... if I
take some random guesses with your schema, and assume you're using a
HABTM join:
SELECT * FROM sub_categories WHERE id IN (
SELECT sub_category_id FROM items_sub_categories WHERE item_id IN (
SELECT id FROM items WHERE category = 'SomeTopic'
)
)
Or you could do that using joins, in a similar manner. It's not so
clean, but put it into the model, and you could get the subcategories
easily enough.
Also, why are you joining and then splitting again?
If you can think of a different method that involves Sphinx, you know
where the code is :)
Cheers
--
Pat
On 30/01/2009, at 10:57 PM, Thibaut Barrère wrote:
>
> Hi,
>
> I have a model with an only one (exclusive) category and several
> possible sub_categories. The sub_categories are stored into a string
> on the AR model and are just comma-separated. I'm able to filter
> properly with both categories and sub-categories.
>
> Now when a category is selected, I need to retrieve the available sub-
> categories to fill a select-box, basically. I found out that this was
> working, thanks to the facets feature:
>
> Item.facets(:conditions => { :category => 'SomeTopic' })
> [:sub_categories].keys.join(',').split(',').uniq.sort
>
> Do you have any idea of some cleaner version, maybe using some built-
> in feature I'm not aware of ?
>
> thanks for any hint,
>
> -- Thibaut
> >
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---