NEWS:

Uncategorized 27 Jun 2005 06:32 pm

odds and ends

It seems that if you use find_first(:id) and are in production you get caching even if :id changes. I had this in several places in clubrs and changing the calls to find() fixed the issue.

This is cool. I use a void field instead of deleting records so FK constraints won’t fail and so the data is there if it ever is needed again.

I had a validation for User :login field:

validates_uniqueness_of :login

And the problem was if a user was voided, the record was still in the db and so the validation would fail, even though I’d like it not to.

Dig into ActiveRecord and find the magic :scope attribute. You send this along and only records that match the value of your new record for the given scope field will be returned:

validates_uniqueness_of :login, :scope => "void"

The new record had a default value of 0 for void; the old voided record had a 1 and so wasn’t considered in the validation.

Worked like a charm. Every time I think I’m going to have to extend the framework or hack around it I seem to find a nice little path already trodden. :)

Comments are closed.