在我的previous issue中,我最后发现以下代码似乎像预期的那样工作:
def my_squeel_query
table_name = Squeel::Nodes::Stub.new("#{self.class.to_s.tableize}_comment_associations".to_sym)
commenters.
.where{
table_name.article_id.eq(my{self.id})
}
end是否可以使article_id 语句与为 table_name 变量所做的动态语句相同?
也就是说,我想做一些如下的事情:
def my_squeel_query
table_name = Squeel::Nodes::Stub.new("#{self.class.to_s.tableize}_comment_associations".to_sym)
commenters.
.where{
table_name.<DYNAMIC_KEY>.eq(my{self.id}) # '<DYNAMIC_KEY>' refers to a column name present in the 'commenters' database table.
}
end发布于 2012-09-27 01:43:07
您可以使用send。
column_name = :article_id
commenters.where{
table_name.send(column_name).eq(my{self.id})
}https://stackoverflow.com/questions/12612889
复制相似问题