Search code examples
rubysequelpadrino

sequel validation check whether name exists in same subcategory


I have an sequel model. I am trying to do validation. I have validation

validates_unique :category

which checks if the same name of category is not taken. It is okay, but I added subcategories (tree). So every record has parent_id if it is subcategory.

I would like to check for duplicates on the same level. I mean that you cannot have duplicate name in top level or in same category, but you can have

buildings
gallery > buildings
names

I was trying to use the examples from documentation, like this

validates_unique(:category, [:category, :parent_id])

to check for combination same parent_id (is number or null) and name. But this makes syntax error

syntax error, unexpected ',', expecting ')'
alidates_unique (:category, [:parent_id, :category])

I tried different combination with parenthesis or without, but with no succes.

validates_unique([:category, :parent_id])

Do you have any clue please?


Solution

  • In method call cannot be a space between method and parameters. Like this

    validates_unique (:category, [:category, :parent_id]) 
    

    It has to be without space

    validates_unique(:category, [:category, :parent_id]) 
    

    I did not see it, in the repetitive readings. Due to tunnel vision and focusing on different parts. I also enlarge my font in my computer. (I have medical issue, loosing sight on right eye).