Granted I''m pretty fresh at ruby, rails, and mysql, but I was poking around active record today, and wondered why a more flexible inheritance model could not be implemented. Specifically if you have many types of users, with differing amounts of data (fields), it doesn''t make sense to use the current inheritance model. For instance if active record looked for a column of name superclass_id instead of just type, it could have both the id and type of the super class. This way you could map the partial info of the child to the superclasses all the way up to Base. The find methods would have to be modified of course so that @attributes would contain all of the attributs of the two+ classes that your object spans. Perhaps it''s messy, or it''s been done, or even more likely I''m simplifying things immensly, but I was just wondering what the general thought on more complex inheritance was. Berndt
There''s been quite a bit of discussion around the inheritance options. If you''re searching the archives try searching for CONTI and CLSTI. In short, yes there are other approaches to implementing inheritance and some people have started looking into them. However I''d be careful, DavidHH may ''volunteer'' you if you post too much on this ;). On Mon, 24 Jan 2005 19:32:56 -0800, Berndt Jung <berndtj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Granted I''m pretty fresh at ruby, rails, and mysql, but I was poking > around active record today, and wondered why a more flexible > inheritance model could not be implemented. Specifically if you have > many types of users, with differing amounts of data (fields), it > doesn''t make sense to use the current inheritance model. > > For instance if active record looked for a column of name > superclass_id instead of just type, it could have both the id and type > of the super class. This way you could map the partial info of the > child to the superclasses all the way up to Base. > > The find methods would have to be modified of course so that > @attributes would contain all of the attributs of the two+ classes > that your object spans. > > Perhaps it''s messy, or it''s been done, or even more likely I''m > simplifying things immensly, but I was just wondering what the general > thought on more complex inheritance was. > > Berndt > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz
Berndt, I have been thinking of this kind of inheritance lately as well. There are some appealing reasons for doing so, one of them being the coincidence of Ruby being a reflective scripting language and Rails being a reflective (naked object) database wrapper. What I mean by this is that with these two tools, it is possible (with much more ease than other tools) to create a web application that creates web applications--right down to the database/model level. I''ve recently been toying with the idea of making an on-line shopping cart that customizes the database itself to reflect the needs of each "store owner." Rather than the traditional approach of having a "categories" table and a "products" table, it would be possible with Ruby on Rails to have the store owner create a class-like hierarchy of tables within the database itself. For example, the "clothes" table could inherit from the "products" table, and "t-shirts" could inherit from the "clothes" table. Each of these tables could potentially be created through a form-based construction method. The user needn''t even know that he or she is creating tables to reflect the particular needs of his or her shopping cart. The flexibility that this method offers is tantalizing :) Duane Johnson (canadaduane) On Tue, 25 Jan 2005 16:49:19 +1300, Michael Koziarski <koziarski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> There''s been quite a bit of discussion around the inheritance options. > If you''re searching the archives try searching for CONTI and CLSTI. > > In short, yes there are other approaches to implementing inheritance > and some people have started looking into them. However I''d be > careful, DavidHH may ''volunteer'' you if you post too much on this ;). > > > On Mon, 24 Jan 2005 19:32:56 -0800, Berndt Jung <berndtj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Granted I''m pretty fresh at ruby, rails, and mysql, but I was poking > > around active record today, and wondered why a more flexible > > inheritance model could not be implemented. Specifically if you have > > many types of users, with differing amounts of data (fields), it > > doesn''t make sense to use the current inheritance model. > > > > For instance if active record looked for a column of name > > superclass_id instead of just type, it could have both the id and type > > of the super class. This way you could map the partial info of the > > child to the superclasses all the way up to Base. > > > > The find methods would have to be modified of course so that > > @attributes would contain all of the attributs of the two+ classes > > that your object spans. > > > > Perhaps it''s messy, or it''s been done, or even more likely I''m > > simplifying things immensly, but I was just wondering what the general > > thought on more complex inheritance was. > > > > Berndt > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > > -- > Cheers > > Koz > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1> I was just wondering what the general thought on more complex > inheritance was.That complexity is typically unnecessary. Single table inheritance should not be discounted because it "seems wrong." Throwing in all the columns you need may upset your aesthetic pleasure center, but STI is simple, fast, and space-efficient. Relational databases are not object-oriented, though we are tempted to treat them as such. There are cases where class table inheritance is a clear winner, but it would be over-prescribed if available. That said, we''re working to add it. In the interim you may emulate it using has_one composition to pull in additional data per-subclass. I recommend Martin Fowler''s Patterns of Enterprise Application Architecture for a great discussion of inheritance mapping: http://www.martinfowler.com/eaaCatalog/ jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (Darwin) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFB9dCJAQHALep9HFYRAgdlAKDeLfZHPDnsSuMnGw6nnACK0eWACwCdGSlk tL/iTAaQhJEhB+vnCdZSUiU=eHgK -----END PGP SIGNATURE-----