Inconsistency in Rails

Good ol’ ActiveRecord::Base has a bunch of “update” methods with arbitrary semantics in regards to object validation:

update(id, attributes) – performs validation
update_all(update, conditions, options) – doesn’t validate, and reverses the operand order (what attributes to change first, followed by the records to change as specified by “conditions”, rather than the other way around). Note also that despite its name it doesn’t (necessarily) update all records.
update_counters(id, counters) – doesn’t validate, reverts operand order

instance methods:

update_attribute(name, value) – doesn’t validate
update_attributes(attributes) – does validate
update_attributes!(attributes) – does validate

A bit of consistency wouldn’t have gone astray. The instance methods are particularly bad – by what rationale does update_attribute not validate while update_attributes does??

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s