Rails 3.2を使用して、列が他のモデルへの参照列であるかどうかを調べる方法はありますか?
名前の「_id」文字列検索に頼りたくありません。
ありがとう。
アップデート:
すべての列を反復する必要があり、次のような参照列で特別な処理を行いました。
result = Hash.new
self.attribute_names.each do |name|
if self[name]
result[name] = self[name]
if name is reference column
insert xxx_description (from the other model) in hash.
end
end
end
このハッシュをjsonとしてクライアントに返します。
{名前: 'ジョセフ', セクターID: 2, セクター名: 'バックエンド'...}
ここで、sector_name は person.sector.name です...
ありがとう。