Add your validation to Branch validates_uniqueness_of :name if you're looking to allow same name between different account, you have to add a scope to it. :scope => :account_id
On Feb 13, 4:18 pm, Zooper <[email protected]> wrote: > I have a situation where accounts have branches and each branch must > have a unique name. I have distilled the essence of the problem in > the models below. I start with a hobo 0.9.106 application and add the > two models and view hint. Starting from this, I do the following: > 1. Add an account and save > 2. Edit the account > 3. Add two branches with the same name > 4. Save the changes > This puts both of the branches with the same name as children of the > account. Since the branch name must be unique this creates other > problems. Is there any way to catch this in validation and not allow > the edit to add duplicate children? > > class Account < ActiveRecord::Base > hobo_model > fields do > name :string > timestamps > end > has_many :branches, :accessible => true > > class Branch < ActiveRecord::Base > hobo_model > fields do > name :string, :unique > timestamps > end > belongs_to :account > > class AccountHints < Hobo::ViewHints > children :branches > end -- You received this message because you are subscribed to the Google Groups "Hobo Users" 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/hobousers?hl=en.
