Hi everyone Recently I thought about adding a feature that allows to find records by values in a serialized field. For example: class Article < ActiveRecord::Base serialize :parameters, Hash end let''s create a sample article to search for: article = Article.new article.title = ''Sample article'' article.parameters = {:foo => "bar"} article.save and then when if we wanted to find that article by its :foo value we could do something like that: article = Article.where(:parameters => {:foo => "bar"}) Of course the syntax is just an example, not sure how could that look if implemented. This would require a database-sided use of regular expressions. But more importantly, would that feature have a use in Rails? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
If you serialize as xml instead of yaml, you can make use of xml query functions if your database supports them... mysql and postgres do at least. On Sun, Apr 10, 2011 at 9:13 AM, Piotr Okoński <piotrek@okonski.org> wrote:> Hi everyone > > Recently I thought about adding a feature that allows to find records > by values in a serialized field. For example: > > class Article < ActiveRecord::Base > serialize :parameters, Hash > end > > let''s create a sample article to search for: > > article = Article.new > article.title = ''Sample article'' > article.parameters = {:foo => "bar"} > article.save > > and then when if we wanted to find that article by its :foo value we > could do something like that: > > article = Article.where(:parameters => {:foo => "bar"}) > > Of course the syntax is just an example, not sure how could that look > if implemented. > > This would require a database-sided use of regular expressions. But > more importantly, would that feature have a use in Rails? > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
This kind of ad-hoc fields, and nested searching is well suited to mongo if you can use it... On 11 April 2011 16:47, Andrew Kaspick <akaspick@gmail.com> wrote:> If you serialize as xml instead of yaml, you can make use of xml query > functions if your database supports them... mysql and postgres do at > least. > > On Sun, Apr 10, 2011 at 9:13 AM, Piotr Okoński <piotrek@okonski.org> > wrote: > > Hi everyone > > > > Recently I thought about adding a feature that allows to find records > > by values in a serialized field. For example: > > > > class Article < ActiveRecord::Base > > serialize :parameters, Hash > > end > > > > let''s create a sample article to search for: > > > > article = Article.new > > article.title = ''Sample article'' > > article.parameters = {:foo => "bar"} > > article.save > > > > and then when if we wanted to find that article by its :foo value we > > could do something like that: > > > > article = Article.where(:parameters => {:foo => "bar"}) > > > > Of course the syntax is just an example, not sure how could that look > > if implemented. > > > > This would require a database-sided use of regular expressions. But > > more importantly, would that feature have a use in Rails? > > > > -- > > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > > To post to this group, send email to rubyonrails-core@googlegroups.com. > > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com. > > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > > > > > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To post to this group, send email to rubyonrails-core@googlegroups.com. > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.