Order of Serializer Validation in Django REST Framework

Situation While working with validation in the Django REST Framework’s ModelSerializer, I have noticed that the Meta.model fields are always validated, even when it does not necessarily make sense to do so. Take the following example for a User model’s serialization: I have an endpoint that creates a user. As such, there is a password … Read more

What is the order of ActiveRecord callbacks and validations?

I was wondering in what order are callbacks and validations called when an ActiveRecord object is created. Let’s say I have some custom validations & callbacks like the following: validates :reference_code, :if => :reference_code, :on => :create before_create :assign_reference which one will run first? The callback needs to happen first or else the validation may … Read more

Validate Before Destroy

I have three classes: School, Account, and Administratorship. School has_many :administatorships has_many :administrators, :through => :administratorships Account has_many :administratorships Administratorship belongs_to :account belongs_to :school before_destroy :confirm_presence_of_alternate_administratorship_in_school protected def confirm_presence_of_alternate_administratorship_in_school unless school.administrators.count([“administratorships.account_id != #{id}”]) > 0 errors.add_to_base “The school must have at least one administrator” end end Now, what I would like to happen is when … Read more

Ruby on Rails: errors.add_to_base vs. errors.add

I have read that errors.add_to_base should be used for errors associated with the object and not a specific attribute. I am having trouble conceptualizing what this means. Could someone provide an example of when I would want to use each? For example, I have a Band model and each Band has a Genre. When I … Read more

Open Graph validation for HTML5

Is there any way to get facebook’s crappy Open Graph meta tags to validate if my doctype is <!DOCTYPE html> (HTML5)? Other than facebook’s Open Graph meta tags, my document validates perfectly. I really don’t want to use <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML+RDFa 1.0//EN” “http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd”> as that creates a whole new set of problems. Here … Read more

Handling Mongoose validation errors – where and how?

I’m trying to decide how I want to handle validation errors in Mongoose. Custom error messages using node-validator I have defined my own validation rules using node-validator, for example: UserSchema.path(‘username’) .validate(function (username) { return validator.check(username).notEmpty() }, ‘Username cannot be blank’) Which will generate an error that looks like this: username: { message: ‘Validator “Username cannot … Read more