Case insensitive uniqueness validation in a Ruby Sequel.migration -
I am trying to find a good validation for using in my migration for which the user will be able to email address Case-insensitive exclusivity will be required. In essence, I should validate I got a comment [1] saying that you can use [1] So I need one of two things: 1) How do I verify a case-insensitive specificity in pure-code I? > Seekel Migration (no ActiveRecord, no rail)? As mentioned in the form of tin man, you are confusing beliefs and constraints. You say that you are trying to add an obstacle and talk about If you want to add a database hurdle, you can do something like this in the migration: It has been done that the database does not permit fake emails in an insensitive way. Validation is to present a good error message to the user before they are saved so that instead of taking exception to the database (which is difficult to deal with difficult), you get a good error message is. In the context of that comment, you can not use validates_unique for the case insensitive lookup on a case-sensitive database without a hack. It will be necessary that validates_unique accept an additional option (which can be added in the future). If you do not want to use a hack like this, you must do the verification manually: In the context of this hack, This is only a hack if the dataset of the model is not already filtered Works. : email, specification = & gt; {: Case_conventional = & gt; False} Without using anything to change the rail or active records, I can run the emails through the rigax but I do not like that solution.
But I do not know what this code is doing and I do not have to use that code when I do not know whether the DS object or what Is happening (why map! , : of Sequel.function in postgrascape is ... less ... maybe, but I just do not Know.)
- OR -
2) What I really want is that code snippet I found online, what does it & amp; how does it work? (What is the DS object and what does this validation with my database?) Sequel.migration , but they have nothing to do with the assumptions.
alter_table (table) {add_unique_constraint Sequel.function (: less, : Email)}
Dataset = Model. Here {| O | {O.lower (: email) = & gt; O.lower (email)}} Dataset. New to index (pk_hash) not new? Errors.add (: Email, 'Already Taken') Unless that ds.count == 0 ds For example validates_unique uses sequel :: dataset to check the specificity if you do validates_unique: email , something like that There will be:
model. ((Email = & gt; email) # WHERE email = 'some email' ds.opts [ : Where] extract from that dataset, and changes the arguments, lapsing them in the SQL less Ta is to transform the function call, where the clause to make it similar to:
model.where {| O | {O.lower (: email) = & gt; O.lower (email)}} # WHERE short (email) = bottom ('some email')
Comments
Post a Comment