class User < ApplicationRecord
has_many :user_youtube_channels
has_many :youtube_channels, through: :user_youtube_channels
・・・
end
class YoutubeChannel < ApplicationRecord
has_many :user_youtube_channels
has_many :user, through: :user_youtube_channels
・・・
end
class UserYoutubeChannel < ApplicationRecord
belongs_to :user
belongs_to :youtube_channel, primary_key: "channel_id", foreign_key: "channel_id"
・・・
end
テーブル間のアソシエーションがこのようになっているとき、
Specの中で
create_list(:user, 2, youtube_channels: [@channel2])のようにして
ユーザーのレコードを2つyoutube_channelsに@channel2が入るようにして作っているのですが、
このとき中間テーブルのUserYoutubeChannelにwatchという付属属性を付けたとき
create_listでwatch属性にtrueを付けて生成するにはどうしたらいいでしょうか。
あなたの回答
tips
プレビュー