From: DCC Date: 2005-10-30T04:17:05+09:00 Subject: Re: The "perfect" ORM? Hal Fulton wrote: > Kirk Haines wrote: > > > > In some cases, you can't do without it. > > > > ORM can be approached from two basic directions. It can be database driven, > > in that the structure of the database dictates the language structures, or > > one can have the language structures dictate the database structure. > > I think I am definitely object-driven. > > [snippage] > > > And the reason why relationships are useful beyond having a simple mapping of > > class to table is because they make the code convenient. > > > > In the MSDS application that my examples come from, one can select a single > > chemical and view information on it. One thing that can be done at that > > point is to see other chemicals manufactured by the same manufacturer that > > the chemical being viewed comes from. > > > > So, if that chemical's record is in @chemical: > > > > @chemical.manufacturer.chemicals > > > > And you have your list. The relationship information provided the necessary > > string to tie those together without the programmer having to explicity write > > the code. It is a tremendous timesaver. > > It is, and I see the usefulness of it, but it doesn't fit my brain. > > That is the sort of thing I'd use a query for, rather than just grabbing the > value of what looks to me like an accessor. I think it's easy to underestimate the value of being able to pass around views of your data as objects. Using a query can will quickly clog up your code (check how clogged up even LINQ queries can become for the coming C# 3.0). I've dramatically reduced the size of some apps using that approach. Then again, there's no point in condensing your code if it doesn't read easily for you. After much resistance my brain now fits in with Kirk's view of things. I see my model as a database and want to design for a database. However, I want my database to be a ruby object. I also want to reduce the number of queries which always introduces errors and debugging for me. This may sound odd, but I want the purity of design of the relational model, as well as the purity of design of ruby OO, without one polluting the other. So I like one layer of my app explicitly for that purpose. > > It's a win if you want to think that way. I'd rather just make the > query syntax easy/flexible and forget about "relates_to" and such. > > I understand a simple query. But every time I saw "relates_to" I > would have to stop and ask myself how it worked and what it meant. You wouldn't call relates_to very much apart from when you initialize the app. I personally find that switching my brain to 'database mode' in those few necessary cases isn't too expensive in runtime. DCC