Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Bug on create unique index with scopes #281

Closed
J-F-Liu opened this issue Apr 13, 2015 · 3 comments
Closed

Bug on create unique index with scopes #281

J-F-Liu opened this issue Apr 13, 2015 · 3 comments
Milestone

Comments

@J-F-Liu
Copy link

J-F-Liu commented Apr 13, 2015

For the following code:
property :modelnumber, String, :unique => [:brand, :name], :required => true

The generated SQL statement is:

CREATE UNIQUE INDEX "unique_products_brand" ON "products" ("modelnumber");
CREATE UNIQUE INDEX "unique_products_name" ON "products" ("modelnumber");

The correct SQL statement should be:
CREATE UNIQUE INDEX "unique_products_modelnumber" ON "products" ("modelnumber", "brand", "name")

@tillsc
Copy link

tillsc commented Apr 13, 2015

Belongs to datamapper/dm-validations#43

@J-F-Liu
Copy link
Author

J-F-Liu commented Apr 13, 2015

The validation works if I first create the table then add the unique argument.
I created a fix on property_set.rb and passed test on table creation, will send PR later.

@tpitale
Copy link
Member

tpitale commented May 24, 2016

@J-F-Liu is the rest of your model like this?

property :name, String
property :brand, String

If so, I think the syntax for a unique index for these fields would be to use a symbol, like this:

property :modelnumber String, unique: :model_brand_name
property :brand String, unique: :model_brand_name
property :name String, unique: :model_brand_name

That is the intended use.

@tpitale tpitale closed this as completed May 24, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants