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) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Apr-23 15:45 UTC
Re: Rails3 how to scope it, using a serialized array ?
On Apr 23, 2:45 pm, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote:> 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 FYF ( For Your Feedback)-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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... On 23 avr, 17:45, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Apr 23, 2:45 pm, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote:> 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 FYF ( For Your Feedback)-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Apr-25 15:25 UTC
Re: Rails3 how to scope it, using a serialized array ?
On Apr 25, 1:18 pm, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote:> 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> > On 23 avr, 17:45, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > On Apr 23, 2:45 pm, Erwin <yves_duf...-ee4meeAH724@public.gmane.org> wrote:> 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 FYF ( For Your Feedback)-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.