私は現在、Rails 3.2 アプリをモデリングしており、「archives」という名前のテーブルに「archivable」という名前のポリモーフィックな関連付けが必要です。心配はいりませんが、「アーカイブ」テーブルも「接続」テーブルに属している必要があります。それを行うためのRailsからの制約があるかどうかを知りたいだけです。
別の詳細として、私の接続モデルには外部キーとして 2 倍の user_id があります。送信者としての user_id と受信者としての user_is。可能?以下で行ったことはうまくいかないと思います...
これが私のモデルの関連付けです。
class User < ActiveRecord::Base
has_many :connections, :foreign_key => :sender
has_many :connections, :foreign_key => :receiver
end
class Connections < ActiveRecord::Base
belongs_to :user
has_many :archives
end
class Archive < ActiveRecord::Base
belongs_to :connection
belongs_to :archivable, :polymorphic => true
end
class Wink < ActiveRecord::Base
has_many :archives, :as => :archivable
end
class Game < ActiveRecord::Base
has_many :archives, :as => :archivable
end
class Message < ActiveRecord::Base
has_many :archives, :as => :archivable
end
Rails で何か間違っていることや実行できないことはありますか?
君たちありがとう。