Here's a little method
So you can write
as an equivalent to
Just a little sugar, nothing else really. Is anyone aware of why that
would be ill-advised? It seems to work with my extremely limited
It's non-orthogonal with respect to association proxies, so maybe that's bad:
MyModel is the same as MyModel.find(12)
MyModel.friends is not the same as MyModel.friends.find(12)
My instinct is to say, "yes, but what happens when record #5 is
deleted?" There are two problems at play:
1) The use of incrementing integers for primary keys (bad, btw, we
need guids much of the time) misleads us into thinking of the table as
an array indexed by the primary keys. It is not. It is a collection
indexed by the primary keys.
2) The use of the operator with integer operands likewise
intuitively directs to an array. But in ruby, a might be the sixth
element of an array, or the value of a hash for the key 5.
Since these classes are mapped to tables, and tables are certainly
collections of rows, then the use of the operator is sensible.
You are not the sole maintainer of this code. Sooner or later,
someone else is going to maintain it. You are changing a base
behavior of the system. Be sure to leave markers.
Is MyModel.friends.find even well defined?