Child pages
  • D2W Create unique index on attribute
Skip to end of metadata
Go to start of metadata

I want to allow users to choose their own login name, however I have to make sure there are no duplicates. Solution, add a distinct index on the Entity/attribute and add a line to the ValidationTemplate.strings.

So in the Entity Modeler notice I added the index. In this case I called it "distinctLogin".

 

You will see this in the migrations like this:

personTable.addIndex(new ERXMigrationIndex(

 "distinctLogin", true, new ColumnIndex("username")

 ));

Now if a user tries to add a login, and that login is in use by someone else, the database will throw a Unique Constraint Exception. We can control the message given to the user in the ValidationTemplate.strings file like this:

{

 "UniqueConstraintException.distinctlogin" = "Please choose a different login name (It must be unique).";

 "Quote.quoteAmount"="You must enter a dollar amount in the format 123.00 (you entered @@escapedValue@@)!";

}

Remember the ValidationTemplate.strings file lives in the <language>.lproj folder.

  • No labels