Activerecord Rules For Duplicates

I am looking at validating if something exists already in the records

i.e. Table

[id][type][setting]

1 2 4

2 3 4

3 2 3

If I try and insert a new entry I need to check if type and setting already exists

So if I were to insert type 2 and 3 I notice that 2 and 3 already exists with the same setting

If I try and insert type 2 and 5 since there is no 5 in type I can add this because it doesn’t follow the same settings already inserted.

I hope that was clear… Is there a way to create this kind of rule or do I have do write a function that manually does this?

check this extension: http://www.yiiframework.com/extension/unique-attributes-validator/

There is also a code example to do the trick without the extension there.