0

Is there a way to specify that a field has to be unique with JayData (same as SQL)?

For example:

$data.Entity.extend("Test", {
    Id: { type: "int", key: true, computed: true },
    Name: { type: "string", required: true, unique: true, maxLength: 200 }
});

If the keyword doesn't exist, how to do it? Actually, I don't want an element to be added if it already exists.

Maxbester
  • 2,435
  • 7
  • 42
  • 70

1 Answers1

0

If you do not need autogenerated id field then declare name as key and computed false so it will be a unique field. If you want to keep the id field then you can use a unique index to achieve what you want. Index support is in the pro providers.

Gabor Dolla
  • 2,680
  • 4
  • 14
  • 13
  • Okay maybe I can try to do without the id field. However I don't understand your second solution. What do you mean by `unique index`? Could you provide an example? Thanks – Maxbester Mar 15 '13 at 10:16
  • We published a blog post about it yesterday. jaydata.org/blog – Gabor Dolla Mar 15 '13 at 12:07
  • I think a professional version is not worth for my app. I will remove the index field. Too bad... Thanks anyway. – Maxbester Mar 15 '13 at 12:23