class Post
has_many :post_categories
has_many :categories, :through => :post_categories
end
class PostCategory
belongs_to :post
belongs_to :category
end
class Category
has_many :post_categories
has_many :posts, :through => :post_categories
end
これは、post_categories が結合テーブルである has_many スルー リレーションシップです。
Post Model に :title というフィールドがあります。投稿内のすべてのタイトルが特定のカテゴリで一意であることを確認する必要があります。結合テーブルの category_id に基づいて検証を実行するにはどうすればよいですか?