I'm not sure I'm 100% clear, but it sounds like you are saying that a
Repair may only have one combination of Part/Product, and it just so
happens that this combination implies a Level. To me the validation
would be:

class Repair < ActiveRecord::Base
  belongs_to :level
  belongs_to :product
  belongs_to :part

  validates_presence_of :level_id, :product_id, :part_id
  validates_uniqueness_of :part_id, :scope => [:product_id]
end

Assuming I understand the problem, I think your confusion stems from
the fact that the level isn't part of what defines a Repair, its
simply an attribute of the Repair. It is really the Part and the
Product that you should be concerned with.

On Feb 21, 7:24 pm, Evan <[email protected]> wrote:
> I just tried this code and was still able to create records with
> different levels for the same part/product combination.
>
> class RepairClass < ActiveRecord::Base
>   belongs_to :level
>   belongs_to :product
>   belongs_to :part
>
>   validates_presence_of :level_id, :product_id, :part_id
>   validates_uniqueness_of :level_id, :scope =>
> [ :product_id, :part_id ]
> end
--~--~---------~--~----~------------~-------~--~----~
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