1

I have the following Models:

Language

Itemtype

Item
    belongs_to :itemtype

LocalisedItem
    belongs_to :item
    belongs_to :language

The LocalisedItem model has an attribute called "title".

I want to validate the uniqueness of said "title" attribute. My problem is the scope: It´s supposed to be unique per language (easy) and itemtype, which I could not figure out how to do until now.

My best try...

validates :title, :uniqueness => { :scope => [:language_id, 'item.itemtype_id'] }

...fails with "NoMethodError: undefined method `item.itemtype_id'".

Is there any way to check for uniqueness in the way described?

4

1 に答える 1

1

この形式を使用して、スコープで一意性を検証できます。

validates_uniqueness_of :title, :scope => :language_id

于 2012-10-22T22:23:13.740 に答える