[Rails] newbie: Single Table Inheritance
Lee Longmore
rubymashup at yahoo.co.uk
Sat Sep 2 20:47:14 GMT 2006
Hello,
I have been experimenting with Single Table Inheritance as described in the More Active Record chapter in Agile Development with Rails.
I have started with an object model with three classes x, y and z (for brevity), where y < x and z < y. (I will want to extend this model further to subclass y with other classes.)
I have created a table called x (plural) in the database with attributes for x, y and z and a type attribute.
I then built a default scaffold application for x and added the subclasses y and z in the model x.rb. Using 'console (irb)' the behaviour is as expected, that is,
z.create(...) - creates a row in the table x with the type = 'z' and the attributes of x, y, z set accordingly.
This is not the case however when I use the scaffold-generated 'create' page. When using this to create rows in table x, the entered attributes (eg, x.a and z.b) are set correctly in the newly created table row but the 'type' is not set (to z). I assume I need to change either the controller or model to get the correct behaviour, and would appreciate some guidance as to how to approach this.
Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060902/c2b14b3f/attachment.html
More information about the Rails
mailing list