constraints

Return Custom Validator Error Grails

耗尽温柔 提交于 2019-12-04 09:53:03
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 You're returning a list containing your message code - you need to return just the code: alternativas validator: { val, obj -> if (val.size()

jQuery UI Draggable Constraint

折月煮酒 提交于 2019-12-04 08:59:29
what I am trying to do is have an large image contained within a smaller div that the user can drag around within the containing div (easy enough)... similar to http://oneblackbear.com/draggable/index.html but I want to prevent users from dragging it any further then the container boundary. With the above example the user can drag the image completely outside of the containing div... I want to prevent the user from ever dragging the image outside of the parent div at all. I have tried using jQuery UI draggable but the problem is if I use the constraint option as soon as you drag the image it

How important are constraints like NOT NULL and FOREIGN KEY if I'll always control my database input with PHP?

こ雲淡風輕ζ 提交于 2019-12-04 08:31:18
问题 I am trying to create a column in a table that's a foreign key, but in MySQL that's more difficult than it should be. It would require me to go back and make certain changes to an already-in-use table. So I wonder, how necessary is it for MySQL to be sure that a certain value is appropriate? Couldn't I just do that with a language like PHP, which I'm using to access this database anyway ? Similarly with NOT NULL. If I only access this database with PHP, couldn't I simply have PHP ensure that

Codeigniter foreign key constraint check

依然范特西╮ 提交于 2019-12-04 07:43:41
Let me first explain the table structure: +-----------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | firstname | varchar(255) | NO | | NULL | | | name | varchar(255) | NO | | NULL | | +-----------+--------------+------+-----+---------+----------------+ The id field is referenced from another table through a foreign key. Say I have a function in my model like this: public function delete_user($id) { return $this->db-

How to use constraint programming for optimizing shopping baskets?

☆樱花仙子☆ 提交于 2019-12-04 07:23:32
I have a list of items I want to buy. The items are offered by different shops and different prices. The shops have individual delivery costs. I'm looking for an optimal shopping strategy (and a java library supporting it) to purchase all of the items with a minimal total price. Example: Item1 is offered at Shop1 for $100, at Shop2 for $111. Item2 is offered at Shop1 for $90, at Shop2 for $85. Delivery cost of Shop1: $10 if total order < $150; $0 otherwise Delivery cost of Shop2: $5 if total order < $50; $0 otherwise If I buy Item1 and Item2 at Shop1 the total cost is $100 + $90 +$0 = $190. If

SQL Server - Cascading DELETE with Recursive Foreign Keys

旧街凉风 提交于 2019-12-04 07:11:04
I've spent a good amount of time trying to figure out how to implement a CASCADE ON DELETE for recursive primary keys on SQL Server for some time now. I've read about triggers, creating temporary tables, etc but have yet to find an answer that will work with my database design. Here is a Boss/Employee database example that will work for demonstration purposes: TABLE employee id|name |boss_id --|---------|------- 1 |John |1 2 |Hillary |1 3 |Hamilton |1 4 |Scott |2 5 |Susan |2 6 |Seth |2 7 |Rick |5 8 |Rachael |5 As you can see, each employee has a boss that is also an employee. So, there is a PK

mysql constarint interval intersection

独自空忆成欢 提交于 2019-12-04 06:54:10
问题 I have mysql table CREATE TABLE `range` ( `id` int(11) NOT NULL, `object_id` int NOT NULL, `datetime_from` datetime NOT NULL, `datetime_to` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Please help to provide on mysql level constraint implementation: no time interval intersection for same object_id. 回答1: A trigger is fine, but by way of demonstrating that no trigger is required, consider the following... DROP TABLE IF EXISTS my_table; CREATE TABLE my_table ( id

OWL Property Restrictions vs. SHACL

北慕城南 提交于 2019-12-04 06:49:47
Given a choice between OWL Property Restrictions and SHACL , is there any reason to choose the OWL approach any more? Particularly with respect to cardinality constraints, I'm wondering whether SHACL is considered to supercede OWL. The syntax appears similar, to my casual inspection. I am probably missing the purpose of OWL cardinality constraints. As part of an ontology, they should facilitate inferencing (a separate concern from validation). But how do cardinality constraints facilitate inferencing? The differences between OWL and SHACL are presented in the table below. | OWL | SHACL | |----

Can you enforce the same constraint on multiple generic type parameters?

匆匆过客 提交于 2019-12-04 06:32:18
问题 I know you can you can do it like this: void M<T1, T2, T3>() where T1 : S where T2 : S where T3 : S {} I want something like this: void M<T1, T2, T3>() where T1, T2, T3 : S {} Is there any such shortcut? 回答1: No, that is not supported. The C# language spec states Each type-parameter-constraint-clause consists of the token where, followed by the name of a type parameter, followed by a colon and the list of constraints for that type parameter. The key here is a , indicating that the grammer

R: from a vector, list all subsets of elements so their sum just passes a value

纵然是瞬间 提交于 2019-12-04 06:26:50
问题 Sorry in advance if the answer (1) is trivial; or (2) out there but I haven't been able to solve this issue or find and answer online. Any pointers will be much appreciated! I am in need of a piece of code that can run through a vector and return all possible subsets of elements whose cumulative sum passes a threshold value. Note that I do not want only the subsets that give me exactly the threshold. The cumulative sum can be above the threshold, as long as the algorithm stops adding an extra