Dedupping Has_many through, :unique=>true

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

On 12/19/06, Dominic S. [email protected] 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

On 12/20/06, Dominic S. [email protected] 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.