For anyone else who has a similar need; to use enums as attributes, the
following approach seems to work (I have an enum called classification which
values 'Reference', "Presentation', etc....

# attributes
has "(case classification when 'Reference' then 1 when 'Presentation' then 2
when 'Book' then 3 else 0 end)", *:as* => *:classification2*, *:type*=> *
:integer*
**
*Cheers,*
*Graham*

On Sun, Dec 7, 2008 at 7:30 PM, Graham Glass <[EMAIL PROTECTED]> wrote:

> Thanks Pat, that's got me going on a good trail I think!
>
> Cheers,
> Graham
>   On Sun, Dec 7, 2008 at 7:25 PM, Pat Allan <[EMAIL PROTECTED]>wrote:
>
>>
>> Hi Graham
>>
>> That's just a placeholder/example MySQL function - I've no idea if
>> there's a function that'll do what you want, but I'm guessing the
>> syntax would look something like that.
>>
>> Cheers
>>
>> --
>> Pat
>>
>> On 08/12/2008, at 2:21 PM, Graham Glass wrote:
>>
>> > Hi Pat,
>> >
>> > Thanks for the hint! I've been reading more of the docs and my next
>> > question is: where does the CONVERT_ENUM_TO_INT function go? Is that
>> > an SQL function or a Ruby/Rails function?
>> >
>> > Cheers,
>> > Graham
>> > On Sun, Dec 7, 2008 at 7:07 PM, Pat Allan <[EMAIL PROTECTED]>
>> > wrote:
>> >
>> > Hi Graham
>> >
>> > I'm not entirely sure how enum's work in MySQL, but if there's a
>> > function you can use/create to translate the values to integers, then
>> > you could wrap it up in your attribute as follows:
>> >
>> > has "CONVERT_ENUM_TO_INT(`enum_col`)", :as => :enum_col, :type
>> > => :integer
>> >
>> > Which would save you from migrating the data.
>> >
>> > Cheers
>> >
>> > --
>> > Pat
>> >
>> > On 08/12/2008, at 12:09 PM, Graham Glass wrote:
>> >
>> > >
>> > > Hi everyone,
>> > >
>> > > One of the columns on my Rails model is represented as an enum in
>> > > MySQL. But Sphinx doesn't seem to allow enums as an attribute type
>> > > which is important to me.
>> > >
>> > > What would you recommend that I migrate my enum column to a simple
>> > > integer and define constants in my application like enum1=1,
>> > enum2=2,
>> > > etc.?
>> > >
>> > > That seems like the simplest solution, but I wanted to get some
>> > > feedback before I proceed.
>> > >
>> > > Thanks,
>> > > Graham
>> > >
>> > > >
>> >
>> >
>> >
>> >
>> >
>> > >
>>
>>
>> >>
>>
>

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