tron wrote:
> class Word
> end
> 
> class PhraseComponent
>    belongs_to :word
>    belongs_to :dictionary_entry
>    acts_as_list :scope => :dictionary_entry
> end
> 
> class DictionaryEntry
>   has_many :phrase_components
>   has_many :words, :through => :phrase_components
> end
> 

Well from the database side of thing that's easily solved by adding a 
unique index across the two foreign keys in the join table. That would 
definitely prevent duplicates in the join table.

CREATE UNIQUE INDEX idx_word_dictionary_entry ON phrase_components 
(word_id, dictionary_entry_id);

>From the Rails side you might be able to use something like the 
following example:

class TeacherSchedule < ActiveRecord::Base
  validates_uniqueness_of :teacher_id, :scope => [:semester_id, 
:class_id]
end

Maybe (untested):

class PhraseComponent < ActiveRecord::Base
  validates_uniqueness_of :word_id, :scope => :dictionary_entry
  validates_uniqueness_of :dictionary_entry_id, :scope => :word_id
end

Note: This may be an expensive method for validating uniqueness!

In any of the cases mentioned you'll still have issues related to 
"Optimistic Concurrency Control:"
http://en.wikipedia.org/wiki/Optimistic_concurrency_control

This section of the Rails documentation has a good explanation of these 
issues and some options on how to solve them:
http://www.railsbrain.com/api/rails-2.2.2/doc/index.html?a=M001824&name=validates_uniqueness_of


-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to