したいので防止レールから"pluralizing"欄でしょうか。
-
19-09-2019 - |
質問
を使用していdwilkieの 外国人 プラグイントです。いテーブル作成る次のように記述されています。
create_table "agents_games", :force => true, :id => false do |t|
t.references :agents, :column => :agent_id, :foreign_key => true, :null => false
t.references :games, :column => :game_id, :foreign_key => true, :null => false
end
しかし、を含むに関連して発生する以下のSQL:
[4;35;1mSQL (2.7ms)[0m [0mCREATE TABLE "agents_games" ("agents_id" integer NOT NULL, "games_id" integer NOT NULL) [0m
たいにカラムと呼ばれるよう agent_id
や game_id
-しない agents_id
や games_id
.したいので防止レールからpluralizingム?
また、以下の私の enviornment.rb
ファイルなユーザー評価:
ActiveSupport::Inflector.inflections do |inflect|
inflect.uncountable "agent_id", "game_id"
end
解決 2
私の問題への解決策を見つけました。私はそうのような言及は別に外部キーを宣言する必要がありました。
create_table "agents_games", :force => true, :id => false do |t|
t.references :agent
t.foreign_key :agents, :column => :agent_id, :null => false
t.references :game
t.foreign_key :games, :column => :game_id, :null => false
end
これで、私は語形のものを取ることができます。
他のヒント
一般的な戦ActiveRecordのコンベンションっていうのはそういうものかAR作業しています。ただし、この 一例 また例外で十分なものコードを取得することができます。rb、チェックアウト http://api.rubyonrails.org/classes/Inflector/Inflections.html のための一例です。
私はあなたがこのように、参照に特異モデル名を使用する場合は、あなたが望む結果を得ると思います:
create_table "agents_games", :force => true, :id => false do |t|
t.references :agent, :foreign_key => true, :null => false
t.references :game, :foreign_key => true, :null => false
end
これは、明確な方法は、結合テーブルの各行は、このように一本のゲームとのエージェントを参照する一AGENT_ID一game_idを有するであろうことを反映している。
追加の変曲または外部キーの宣言は、この場合には必要ではないでしょう。