On Saturday, February 8, 2014 2:34:35 AM UTC-8, Brave Dick wrote:
>
> User:
>
> class User < Sequel::Model
> many_to_many :documents
> self.raise_on_save_failure = false
> plugin :validation_helpers
> def validate
> super
> validates_format /@/, :email
> validates_presence [:password]
> validates_unique :email
> end
>
> def before_save
> super
> self[:password] = BCrypt::Password.create(self[:password])
> end
> end
>
> Update:
>
> def updateUser(userData)
> user = User.where(id: userData[:id]).update(
> email: userData[:email]
>
> )
> end
>
> Works with userData[:email] => '1111', but should not (doesn't has '@')
>

You are calling Dataset#update to update a set of records, not Model#update 
to update a single record.  Dataset#update doesn't run validations, it just 
issues an SQL query.  Either do:

  user = User.first(id: userData[:id]).update(email: userData[:email])
  # or
  user = User[userDate[:id]].update(email: userData[:email])

Or better yet, add a database constraint so that your validations are 
enforced in the database (the constraint_validations extension can help 
with that, assuming you aren't using MySQL).

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to