Rails3 how to scope it, using a serialized array ?

giving a simple model, with a serialized Array attribute

class Instructor < User ..   serialize :languages, Array

I am looking in defining scopes like this :

scope speaking_english, lambda { where("languages ... includes.... ?", :en) }

which look for instructors in which the languages array include ":en"

Is this kind of scope possible ? or not.... ( just using query )

thanks FYF ( For Your Feedback)

giving a simple model, with a serialized Array attribute

class Instructor < User .. serialize :languages, Array

I am looking in defining scopes like this :

>scope speaking_english, lambda { where("languages ... includes.... ?", :en) }

which look for instructors in which the languages array include ":en"

Is this kind of scope possible ? or not.... ( just using query )

You probably can mash something together with a regular expression (although it might be hard to cover all edge cases), but this sounds to me like you shouldn't be using serialize, since it makes this sort of stuff awkward (and slow, since you can't add indexes that will support that sort of query). With a separate join table between users and languages it all becomes very simple.

Fred

Thanks Fred for your advice .. this is what I finally did... I just keep serializing parameters for being used with a proxy object connector to external services , as the parameters to be used are different from one connector to another one...

Thanks Fred for your advice .. this is what I finally did... I just keep serializing parameters for being used with a proxy object connector to external services , as the parameters to be used are different from one connector to another one...

You might want to look at a document store like mongodb, these allow you to store more complex objects as a single document, while still be able to query "inside" them

Fred