如何检索active_record生成的别名?我想创建一个方法table_alias_of,它接受3个参数
解决条件或顺序中的关联。
示例:所有包含指向同一个表“联系人”。
includes = ["end_user", "reseller", "distributor"]
e = table_alias_of(Maintenance, includes, "end_user")
e #=> contacts
r = table_alias_of(Maintenance, includes, "reseller")
r #=> maintenances_contacts
d = table_alias_of(Maintenance, includes, "distributor")
d #=> maintenances_contacts_2
Maintenance.all(
:include => includes,
:conditions => ["#{d}.name=?", x],
:order => "#{r}.name, #{e}.name"
我怎样才能实现table_alias_of?它应与rails 2.3.x以及rails 3.1.x
兼容我已经做过/想到的是