Newbie : Easiest way to validate uniqueness of 2 fields that are related

Hello everyone

Just to be sure, what is the easiest way to validate that a
combination of 2 fields is unique in my model ?

Example :

I have Posts and Comments

A posts can have multiple comments (so post_id is not unique) and
multiple comments can have the same title (title is not unique
either).

But, I don’t want 2 comments from the same post to have the same
title. How is the easiest way to test that in my Comment model ?

On Jun 21, 8:27 pm, DavidPaquet [email protected] wrote:

Hello everyone

Just to be sure, what is the easiest way to validate that a
combination of 2 fields is unique in my model ?

That’s what the :scope option on validates_uniqueness is for.

Fred