Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enter unique associations only?

Running the following code to add an association enters multiple entries each time the code is ran:

store.categories << category

Is there a way to make it only enter unique associations between the two models in the db?

like image 707
Hopstream Avatar asked Nov 07 '11 03:11

Hopstream


Video Answer


1 Answers

Directly from the rails guides, hope it helps:

class Person
  has_many :readings
  has_many :posts, :through => :readings, :uniq => true
end
like image 185
fuzzyalej Avatar answered Oct 12 '22 18:10

fuzzyalej