# Dedupping Has\_many through, :unique=\>true

**URL:** <https://www.ruby-forum.com/t/dedupping-has-many-through-unique-true/79867>\
**Category:** Rails\
**Created:** [December 20, 2006, 12:13am UTC](https://www.ruby-forum.com/t/dedupping-has-many-through-unique-true/79867 "2006-12-20T00:13:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![3nd3r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/3/c4cdca/32.png) [@3nd3r](https://www.ruby-forum.com/u/3nd3r)\
**Post date:** [December 20, 2006, 12:13am UTC](https://www.ruby-forum.com/t/dedupping-has-many-through-unique-true/79867/1 "2006-12-20T00:13:29Z")

</div>

Hi, In the Agile book, it is told that by putting a :unique =\> true will  
dedup the row with ActiveRecord.

But it’s not working out for me. Do I need edge rails for this?

I simply want to dedup any join model associations, for instance:

category\_id | inventory\_id  
384 1 first entry  
384 2 this would be ok.  
384 1 this would not be ok

Any help is appreciated. Thanks

---

<div class="post-metadata">

**Author:** ![3nd3r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/3/c4cdca/32.png) [@3nd3r](https://www.ruby-forum.com/u/3nd3r)\
**Post date:** [December 20, 2006, 5:59pm UTC](https://www.ruby-forum.com/t/dedupping-has-many-through-unique-true/79867/2 "2006-12-20T17:59:37Z")

</div>

On 12/19/06, Dominic S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi, In the Agile book, it is told that by putting a :unique =\> true will  
> dedup the row with ActiveRecord.
> 
> But it’s not working out for me. Do I need edge rails for this?

Use :uniq =\> true (note the spelling which matches Ruby’s Array#uniq  
method)  
on 1.2 or later.

jeremy

---

<div class="post-metadata">

**Author:** ![3nd3r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/3/c4cdca/32.png) [@3nd3r](https://www.ruby-forum.com/u/3nd3r)\
**Post date:** [December 21, 2006, 12:02am UTC](https://www.ruby-forum.com/t/dedupping-has-many-through-unique-true/79867/3 "2006-12-21T00:02:51Z")

</div>

On 12/20/06, Dominic S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 384 1 first entry  
> 384 2 this would be ok.  
> 384 1 this would not be ok
> 
> Any help is appreciated. Thanks

I’m not 100% on :unique =\> true but you should be able to put validation  
into your join model to prevent these kinds of issues.

eg

validates\_uniqueness\_of :category\_id, :scope =\> :inventory\_id

might do the trick.
