Re: [Modeling-users] UNIQUE columns
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2005-05-31 20:48:52
|
Hi James, James Laska <ja...@gm...> wrote: > Hello, >=20 > Is there a method for tagging a column as UNIQUE so that multiple > copies cannot be inserted into the database? I do not see a isUnique > property in any of the attributes. Am I looking in the wrong place or > is there an alternative way to define this? Is this simply a method > of defining multiple primaryKeys for an entity (although that does not > appear to be valid)? Well, there is no method for this working "out of the box". Multiple primary keys are not supported yet, and I've currently no idea how long it could take implementing that. The simplest method is certainly to declare 'UNIQUE' the row you want to be unique --and/or add whatever constraint you need in the database schema. Doing this, you're sure that you'll get an error when trying to saveChanges(). However, you're not going to get an error at validation time, which is maybe something you'd like to get (even if business logic cannot *guarantee* that the value will be unique in the db at the time when it is actually commited in the db). If you want to go that way, you'll probably want to check whether ec.fetchCount() returns >1 when asked, say, for entity 'Book' and qualifier 'book.title=3D"The Hitchhiker's Guide to the Galaxy", if this is the value self.title and you want 'title' to be unique. Got the idea? -- S=E9bastien. |