From: Kirk Haines Date: 2005-10-28T06:31:32+09:00 Subject: Re: The "perfect" ORM? On Thursday 27 October 2005 1:57 pm, rubyhacker@gmail.com wrote: > This is only my opinion. > > I dislike putting the metadata for my objects into the objects > themselves. > > As someone pointed out, if I "reopen" the class, it is a little > better, but I am still unconfortable this way. > > In addition, my memory of Og is that it encourages thinking in > database terms (like "has_many") -- true or not? This is a hard thing to deal with, though. A relational database has to use keys to implement relationships between the tables. Some databases make it very clear what the relationship is. If the database has a foreign key constraint on a table, this means that the database is saying that field X in the table references field Y in another table. If a database supports this sort of thing, then the ORM can automatically tell from the database structure that one table, and thus, one object, has a relationship with another. It can create that relationship for you. But if you start from the other end, with the objects, you are not starting with any of that meta information, so you have to do something to identify classes which should map to tables, and if you intend for one field to store only objects or arrays of objects of another class which is also represented in the db by a table, you have to do something on the ruby side to declare that. The has_one, has_many, many_to_many, and similar terms are commonly accepted terms for describing these relationships. In thinking a bit about it, though, I do suppose that one need not need to actually use those terms. I could pretty easily make the following work in Kansas today. class Schools # The line below would indicate that there is a one to many relationship # between a school and the inventories. So one school can be associated # with many inventory records. relationship Inventories.school_idx end class Inventories # This line indicates that there is a one to one relationship between # an Inventories object (and thus, db record) and a Chemicals object. relationship chemical_idx => Chemicals end > 3. To store the metadata separately from my classes/objects so as to > minimize impact on them. (But probably not in a separate file.) I am not seeing why it would be beneficial to keep this annotation seperate from the classes. The information has to be looked up somewhere, and if the annotation doesn't interfere with the class otherwise, what is the downside to having that information attached? If it is seperate, you still have to, somehow, associate the two, and the information still needs to be looked up. What is the benefit? Kirk Haines