ロボットと人間の 2 つのモデルがあるとします。
次のいずれかの関連付けを行うことは可能ですか?
Robot has_one Human and Human has_one Robot
Robot has_one Human and Human has_many Robots
t.integer :robot_id
また、人間の移行ファイルまたはt.integer :human_id
ロボットの移行ファイルにどのような場合に含める必要がありますか?
ロボットと人間の 2 つのモデルがあるとします。
次のいずれかの関連付けを行うことは可能ですか?
Robot has_one Human and Human has_one Robot
Robot has_one Human and Human has_many Robots
t.integer :robot_id
また、人間の移行ファイルまたはt.integer :human_id
ロボットの移行ファイルにどのような場合に含める必要がありますか?
has_and_belongs_to_manyを探しているようです。あなたの質問を正しく読めば、まさにあなたが考えていることを実行できます。
機能させるには結合テーブルが必要ですが、それは非常に簡単です。乾杯!