I'm trying to implement validation in Doctrine. Doctrine by default inserts any size string. If it's too big, then it inserts first N characters into the database.
If the max column length is 7, then this happens:
To be inserted: 'www.google.com'
Result: 'www.goo'
How do I get Doctrine to come back with an exception? I don't want to hard code the maximum lengths in my validator.
Doctrine won't validate the string length, see http://docs.doctrine-project.org/en/latest/reference/annotations-reference.html#column.
You should validate all input values yourself using validators before passing it to the Doctrine entity. What's the problem of defining maximum lengths in your validator?
Related
I would like to retrieve records of kiscourse where the related joblist.job has a value that contains tech within the joblist.job string value.
This returns the expected results:
/joblist?select=job,kiscourse_id(*)&limit=10&job=ilike.*tech*
This does not:
/kiscourse?select=*,joblist(*)&limit=10&joblist.job=ilike.*tech*
And according to: https://postgrest.com/en/v4.1/api.html#embedded-filters-and-order, this seems to be the intended:
> GET /films?select=*,roles(*)&roles.character=in.Chico,Harpo,Groucho
> HTTP/1.1
Once again, this restricts the roles included to certain characters
but does not filter the films in any way. Films without any of those
characters would be included along with empty character lists.
Is there any way to accomplish the above (besides procedures)?
the joblist.job filter you have there will affect only the entities on the second level, it does not apply to the first level.
The way to read this query
/kiscourse?select=*,joblist(*)&limit=10&joblist.job=ilike.*tech*
is this:
Give me 10 rows from kiscourse with all the columns, and for each row, i want the joblists for that row that are named *tech*
Trying to build a barebones concept in Ruby on Rails that will take a string, map each individual word in this string, compare it and then substitute the word if it matches predefined strings in related databases.
For example: User inputs in text field "What does lol and brb mean?" Hits Submit button. The action gives back the same text with "lol" and "brb" changed to "laughing out loud" and "be right back".
So far I have a Post model & table for the User input that stores the string in the database.
I have an Acronym model & table that has "lol" and "brb" stored in database with a foreign key reference to Acronym_Translate model & table that has "laughing out loud" and "be right back" referenced to "lol" and "brb", respectively.
How would I connect the Post model/table to the Acronym model/table in order to compare the strings in Post and substitute with strings from Acronym model/table? And what command could achieve such function? Would gsub! method work here?
Any help would be appreciated!
Are you sure that you want to connect the Post table to the Acronym table? This means that you would have to identify and keep a record of each instance of an acronym within a post.
You can do this using a many to many relation or if you want to store extra data about each acronym occurrence you should create a link table named AcronymPost and use a has many through relationship between Post and Acronym. When you parse a post value, and when you identify an acronym in the post, you would have to record this in the database and then use gsub to replace the post value with the acronym.
You can iterate through your table of acronyms and use (string).include? method to check if it occurs in the post. Finally, you could use a gsub command to replace the acronym with its translation.
I am trying to fetch records from ExtJS store which start with specific substring.
e.g. If I have a country store and if I have a string 'IN' then I want records of India and Indonesia from store.
Is there any way to do this?
Thanks
I suppose this is about a combobox, so that's the default behavior.
For example: https://fiddle.sencha.com/#fiddle/11r4
If you just want to filter a store, look at:
filters config - Array of Filters for this store.
filter method - Filters the data in the Store by one or more fields.
filterBy method - Filters by a function.
Ext.util.Filter - Represents a filter that can be applied to a MixedCollection.
I have one scenario, in which I am searching a no pan string in a documents. In my application, we are sending two query request to SOLR i.e one is with Exact query(i.e phrase query) which returns me Exact results and next query is AND query. But it happens that the results of Exact query are also contains in the AND query, so I want to remove that records from AND query results. So its possible to remove from SOLR end?
I am using sunspot gem and rails.
If your document contains any unique field then use that field in second query as a not in query.
for example if you have id as unique field.
Then from the first query you get those ids
and put in the second query as
-id:(123 OR 345)
So from the second queries result these will get filtered...
Or simply you can re-formulate the second request to include AND but exclude the exact matches.
The updated second request becomes a negation of the current first request (exclude exact matches) combined with your current second request (via an and operation).
I wish to create a model where I can store a string formatting pattern as well as accompanying values.
Example:
Pattern = 'Strength deals %d more damage for each %f%% critical chance'
Values = [2, 1.50]
The pattern only has to store ints and floats. My initial thought was to simply create a custom field, validate the values and that would be it. You can see my field here
However, this simply lets me save the list. I still need some way to figure out how many values to validate, check that it matches the other field (a simple CharField). This could be done "manually", but I would like to create a custom form field that would generate X input boxes that match the number of wildcards in the pattern.
Question 1: Is there any way to "link" two fields so that one can act on the value of the other?
Question 2: To create this, I would probably need to create a new form widget, but is this possible? Any hints as to how to start?
This may not exact answer, but writing it in comment is not feasible.
Another option would to store as JSON string in the model. Like
[{ "Pattern": 'Strength deals %d more damage for each %f%% critical chance',
"Values" : [2, 1.50]
}]
Use custom form field to input/output as JSON input. There are quite a few implementation available when searched on google.
With this approach, you can try to validate the inputs, so that format string and number of variables provided matches.