constraints

Angular route parameters contraints

让人想犯罪 __ 提交于 2019-12-06 09:19:09
问题 I'm coming from the Asp.net MVC world where route constraints are really useful. I'm currently developing an Angular JS SPA that incorporates client side routing. I would also like to add parameter constraints to my client-side routes as in: $.routeProvider.when("/post/:id/:name?") where I'd like to constrain my :id parameter to only be valid when these are numbers. I haven't found anything similar in Angular Docs (which are horrible to say the least). Can it be done? And maybe also parameter

Access Auto Layout Constraint Programmatically

女生的网名这么多〃 提交于 2019-12-06 07:48:48
问题 I have a view that has a lot of subviews, I will refer to these views as superview, subview A, subview B, subview C, etc. So I need to access the trailing space constraint I set on subView A to superview and modify it. This constraint would appear in superview.constraints. However, all the subviews have leading/trailing space constraints set between them and the superview. So, if I log superview.constraints, it would look like this: <__NSArrayM 0xac744e0>( <NSLayoutConstraint:0x98f3500 H:|-(0

Django: apply “same parent” constraint to ManyToManyField mapping to self

为君一笑 提交于 2019-12-06 07:03:21
问题 I have a model where tasks are pieces of work that each may depend on some number of other tasks to complete before it can start. Tasks are grouped into jobs, and I want to disallow dependencies between jobs. This is the relevant subset of my model: class Job(models.Model): name = models.CharField(max_length=60, unique=True) class Task(models.Model): job = models.ForeignKey(Job) prerequisites = models.ManyToManyField( 'self', symmetrical=False, related_name="dependents", blank=True) Is there

Unique Constraint for Bit Column Allowing Only 1 True (1) Value

情到浓时终转凉″ 提交于 2019-12-06 06:02:30
问题 I have this table: CREATE TABLE [tblExample]( [ExampleID] [int] IDENTITY(1,1) NOT NULL, [WordsAndStuff] [nvarchar](max) NOT NULL, [Active] [bit] NOT NULL I want the Active column to have a unique constraint that will only allow one record to be true (1). At this point, I don't need there to BE a true record all the time, there just cannot be more than one of them. How do I write the constraint? 回答1: Just one active record at a time in the table? You can use a unique index with a filter:

Return Custom Validator Error Grails

血红的双手。 提交于 2019-12-06 04:49:38
问题 I'm only getting the default validator message. What am I doing wrong? class Questao { static hasMany = [alternativas:Alternativa] static constraints = { alternativas (validator: {val, obj -> if(val.size() < 2) return ['validator.message'] //custom message }) } } /i18n questao.alternativas.validator.message = "must be greater than two" default.invalid.validator.message= Property [{0}] of class [{1}] with value [{2}] does not pass custom validation Thanks 回答1: You're returning a list

SQL Server add a column constraint to limit data to -1 to 1

一世执手 提交于 2019-12-06 04:45:50
问题 I want to constrain a SQL Server decimal column to only allow -1,0,1 as valid values. Can you show me the SQL syntax for adding such a constraint. (I would like to know how to do it in both the CREATE TABLE statement and/or the ALTER TABLE ADD CONSTRAINT). Or can this only be accomplished in a trigger? 回答1: CREATE TABLE foo ( bar int NOT NULL CONSTRAINT CK_foo_bar CHECK (bar IN (-1, 0, 1)) ) or ALTER TABLE foo WITH CHECK ADD --added WITH CHECK CONSTRAINT CK_foo_bar CHECK (bar IN (-1, 0, 1)) -

Hibernate: constraintName is null in MySQL

柔情痞子 提交于 2019-12-06 04:40:50
I have a code using JPA with Hibernate 3.3.x. This Java code can be used with schemas stored either on Oracle 10g or MySQL 5.1.x. Tables are defined with constraints to define unique records. When a constraint violation occurs, I want to retrieve the constraint name from the exception. With Oracle, the constraint name is properly retrieved. With MySQL, the constraint name is NULL . Any idea how to get the constraint name with MySQL? Thanks Said I've come up with the following solution: Extend existing Hibernate MySQL5Dialect: public class MySQL5Dialect extends org.hibernate.dialect

Implementing table level check constraint

萝らか妹 提交于 2019-12-06 03:46:58
We have a table that contains prices that are depending on a base amount. As an example let say that if the base amount is less or equal to 100 then the price is 10 but if the base amount is greater that 100 but less or equal to 1000 then the price is 20 and finally if the base amount is greater than 1000 then the price is 30. A simplified version of our table for this should be something like this: PRICE_CODE START_RANGE END_RANGE PRICE_AMOUNT 100 0,00 100,00 10,00 100 100,01 1000,00 20,00 100 1000,01 99999999,99 30,00 110 0,00 99999999,99 15,00 With columns level check constraints you can

Create custom error message MySQL

▼魔方 西西 提交于 2019-12-06 03:36:19
问题 In MySQL, how to create custom message for this error message: Cannot delete or update a parent row: a foreign key constraint fails ( database . jenis_fasum , CONSTRAINT jenis_fasum_ibfk_1 FOREIGN KEY ( id_kategori ) REFERENCES kategori_fasum ( id_kategori )) Using trigger maybe? Can someone provide an example? Thanks for your help 回答1: I don't think it can be done in a TRIGGER , but it can be done with a stored procedure in MySQL 5.5. Here's the default error message: mysql> INSERT INTO area

Index of string value in MiniZinc array

落花浮王杯 提交于 2019-12-06 02:56:08
The question Given a MiniZinc array of strings: int: numStats; set of int: Stats = 1..numStats; array[Stats] of string: statNames; ... with data loaded from a MiniZinc data file: numStats = 3; statNames = ["HEALTH", "ARMOR", "MANA"]; How can one look up the index of a specific string in the array? For example, that ARMOR is located at position 2. The context I need to find an optimal selection of items with regard to some constraints on their stats. This information is stored in a 2D array declared as follows: int: numItems; set of int: Items = 1..numItems; array[Items, Stats] of float: