Validates_uniqueness_of :scope => association

(How?) Is it possible to use validates_uniqueness_of with a scope that
is a
belongs_to association?

This is what I would like to do:

class Lot < ActiveRecord::Base
belongs_to :part, :include => true
validates_uniqueness_of :identifier, :scope => :part
end

…but (not surprisingly) when I run my unit test, I get:

ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column:
lots.part

Basically, I want to ensure that identifiers are unique for a given
part.

I think I’m going to have to write my own validation here, but I thought
I
would ask the question first.

–wpd

On Sep 15, 9:44 pm, Patrick D. [email protected] wrote:

…but (not surprisingly) when I run my unit test, I get:

ActiveRecord::StatementInvalid: SQLite3::SQLException: no such column:
lots.part

Basically, I want to ensure that identifiers are unique for a given part.

I think I’m going to have to write my own validation here, but I thought I
would ask the question first.

Well validates uniqueness of wants scope to be column, so give it one
(part_id) !

Fred

On Tue, Sep 15, 2009 at 5:57 PM, Frederick C. <
[email protected]> wrote:

Basically, I want to ensure that identifiers are unique for a given part.

Well validates uniqueness of wants scope to be column, so give it one
(part_id) !

Fred

Oh… duh!
(sheepishly creeps back into his cave with very little light)

Thanks Fred.

And thanks for answering such blatantly simple questions.

–wpd