如何在mongoid上按名称查询字段?
How to query a field by name on mongoid?
如何获得相同查询的结果:
Test.where(name: "Depeche Mode").first.last_connection_date
通过字符串更改 last_connection_date
@desired_field = "last_connection_date"
Test.where(name: "Depeche Mode").first.(@desired_field)
你可以利用send
Test.where(name: "Depeche Mode").send(@desired_field.to_sym)
如何获得相同查询的结果:
Test.where(name: "Depeche Mode").first.last_connection_date
通过字符串更改 last_connection_date
@desired_field = "last_connection_date"
Test.where(name: "Depeche Mode").first.(@desired_field)
你可以利用send
Test.where(name: "Depeche Mode").send(@desired_field.to_sym)