On Tuesday, August 26, 2014 2:59:16 PM UTC-7, DaVinci wrote:
>
> Hi again (so many Sequel experiments in my mind now ;) 
>
> I have been testing these two plugins: 
>
>   * nested_attributes 
>   * class_table_inheritance 
>
> in my Model. My hope was that nested_attributes managed CTI transparently, 
> but 
> it seems not the case. Let's see what I have: 
>
> -------------------------------------- 
> class Container < Sequel::Model 
>   one_to_many :contents 
> end 
>
> class Content < Sequel::Model 
>   plugin :class_table_inheritance 
> end 
>
> class CubicalContent < Content 
> end 
>
> class ConicalContent < Content 
> end 
>
> class SphericalContent < Content 
> end 
> ------------------------------------- 
>
> With this model if I use nested attributes for creating with: 
>
>   {contents_attributes: 
>     [ 
>       {kind: 'CubicalContent', cubical_data: 'bla'}, 
>       {kind: 'ConicalContent', conical_data: 'ble'}, 
>       {kind: 'SphericalContent', spherical_data: 'bli'} 
>     ] 
>   } 
>
> I get no specific class objects, but a collection of bare Content 
> instances. 
> I know that this is a good deal of magic, but CTI is a great plugin for 
> quality modeling. If only we could use nested attributes for 
> creating/updating 
> transparently without annoying corner cases, that would be great :) 
>

I don't think you'll be able to get that to work.  With CTI, 
Superclass.new(:kind=>'Subclass') gives you an instance of Superclass, not 
Subclass.  However, if you reload the contents from the database, Subclass 
instances should be returned.

Personally, I think CTI is a bad pattern for modeling.  Favor 
composition/associations over inheritance.  Attempting to emulate 
inheritance in the database using multiple tables is a bad idea, IMO.  I 
wrote the CTI plugin to show that Sequel can handle it, not because it is a 
good pattern to use.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to