What is it about the config/vhost.yml file that would make this unique
index on the "name" attribute go away?

On a related note it looks like sqlite requires that all indexed
columns be unique!
SQLite3::ConstraintException: indexed columns are not unique: CREATE
UNIQUE INDEX "name" ON "snippets" ("name")

Has anyone run into this before?


On Feb 14, 12:50 am, Haselwanter Edmund <edm...@haselwanter.com>
wrote:
>   Snippet:
>     name:
>       message:
>         'Name wurde schon verwendet'
>       scope:
>         site_id
>
> in config/vhost.yml
>
> should do the trick ...
>
> On 14.02.2011, at 09:14, craayzie wrote:
>
>
>
>
>
>
>
>
>
> > So weird. I run the migration but it does nothing to db/schema.rb:
>
> >  add_index "snippets", ["name", "site_id"], :name =>
> > "index_snippets_on_name_and_site_id", :unique => true
> >  add_index "snippets", ["name"], :name => "name", :unique => true
>
> > Here's the exact migration:
>
> > $ cat db/migrate/004_migration4.rb
> > class AddSiteIdIndex < ActiveRecord::Migration
> >  def self.up
> >    remove_index :snippets, :name
> >  end
>
> >  def self.down
> >    add_index "snippets", ["name"], :name => "name", :unique => true
> >  end
> > end
>
> > Any ideas?
>
> > On Feb 13, 11:50 pm, William Ross <w...@spanner.org> wrote:
> >> On 14 Feb 2011, at 05:46, craayzie wrote:
>
> >>> So this appears to be simple issue of the Snippets model validation
> >>> not being updated. I know the proper way to do this is to create an
> >>> ActiveRecord migration but just to see it work I hand-edited vendor/
> >>> radiant/app/models/snippet.rb
>
> >>> - validates_uniqueness_of :name, :scope
> >>> + validates_uniqueness_of :name, :scope => :site_id
>
> >>> I then ran 'rake db:migrate' but nothing changed? Did I miss a step?
>
> >> Slight muddle there: migrations change the database columns. Validations 
> >> are applied in the model before the object is saved to the database.
>
> >> In the case of Snippets you have both kinds: there's a uniqueness 
> >> constraint in the database which is supported by a validates_uniqueness 
> >> call in the model class so that we can return advisory messages rather 
> >> than just throwing errors.
>
> >> I don't know what the current situation is with the vhost extension but 
> >> your fix to the validates_uniqueness call is right and you can remove the 
> >> uniqueness constraint from the database with this migration:
>
> >>         remove_index :snippets, :name
>
> >> You'll find similar validations on Layout and User but perhaps those won't 
> >> matter.
>
> >> best,
>
> >> will
>
> --
> DI Edmund Haselwanter, 
> edm...@haselwanter.com,http://edmund.haselwanter.com/http://www.iteh.at|http://facebook.com/iTeh.solutions|http://at.linkedin.com/in/haselwanteredmund

Reply via email to