LoginSignup
1
0

More than 3 years have passed since last update.

[rails] Modelに紐づく関連テーブル名一覧を取得するメモ

Posted at
User.reflect_on_all_associations.map(&:name)
=> [:orders, :address, :payments]
# has_one等を指定する事も出来る
User.reflect_on_all_associations(:has_one).map(&:name)
=> [:address]

参考
reflect_on_all_associations

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0