On Sat, May 12, 2007 at 12:30:00AM +0900, Bernd B. wrote:
But this solution to me seems to be so un-ruby!
You seem to be doing something very strange in the above code. You are
replacing one of ActiveRecord::Base’s most fundamental operations - load
from database by ID - with something which does something completely
Are you also going to overwrite the save and update methods? In which
what functionality from ActiveRecord::Base do you actually want to keep?
I am guessing that SAP4Rails is some sort of remote-procedure call
That is, an instance of SAP4Rails::Base represents an object on some
SAP server. If that’s true, I don’t see how it makes sense to try to mix
that with another object which represents a row in a local SQL database.
If Myclass represents something which may exist in the local database
in the remote SAP system, then I’d very much go for delegation.
class MyDb < ActiveRecord::Base; end
class MySap < SAP4Rails::Base; end
@rec = MyDb.find(number)
@sap = MySap.find(number)
Then you are making it explicit that you are talking about two different
things, and you can implement useful operations (such as copy data from
to the other)