I have an application where I want to migrate from MetaWhere to Squeel in preparation for an upgrade to Rails 3.1.
This has been mostly a simple process but I have one case that causes me a bit of problems. The problem is that I have both the field and the value specified as variables. In my MetaWhere queries I could simply create symbols out of the field names and then us开发者_开发百科e that in the query but Squeel does not use symbols but instead relies on instance_eval and I cannot figure out how to create a similar query using that...
An illustration of the original query could be:
Article.where("#{field_name}".to_sym.matches => '%' + field_value + '%')
How do I create a similar query in Squeel?
I know I can specify that I want to use the legacy symbol functionality but I would rather fully convert to the new syntax.
This works:
Article.where{article.send(field_name) =~ '%' + field_value + '%'}
The lowercase 'article' being the table name.
精彩评论