Single table inheritance... in multiple tables

0 views
Skip to first unread message

Gareth Adams

unread,
Aug 31, 2006, 6:48:14 AM8/31/06
to rubyonra...@googlegroups.com
Hi all,

I like how single table inheritance works, in that you can share functionality
and validation etc between related models. The only thing I don't like is that
everything gets mixed into the same table. Quite often I end up with a lot of
redundant fields in a lot of records.

Is there any way to cause inheritance without triggering the STI special
behaviour?

Lee

unread,
Sep 5, 2006, 10:10:18 AM9/5/06
to Ruby on Rails: Talk
Gareth, I too wasn't too happy with some aspects of STI, but to be fair
the constraints are pointed out in the Agile Rails book.

I am going to try the following for the scenarion where a number of z
subclasses inherit from a single y class which in turn inherits from a
single x class, and where z subclasses may be very different from
eachother.


The solution I plan to try is:


1) One controller with a new() action that instantiates the base class
(x) and correct subclasses (y,z) for the input form data (using a
'type' selected in the UI)
2) Create action that saves x and thru table association (e.g. has one,

belongs to) saves the appropriate subclasses (y,z).
3) Individual models - one for x and y, and one for each sub class z.

Regards,
Lee.

Reply all
Reply to author
Forward
0 new messages