On Tuesday, August 26, 2014 3:40:26 PM UTC-7, DaVinci wrote:
>
> El miércoles 27 de agosto, Jeremy Evans escribió:
> > 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.
>
> I have seen code and that behaviour is correct. Only posible solution
> would be
> that nested_attributes knew of CTI and search for specific :kind in data
> before
> trying to create instance.
>
> > 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.
>
> In your opinion, what should be good strategy for my previous message
> example?
>
Assuming you were using PostgreSQL, a json/hstore column for columns not in
the parent class should work really well in most cases.
In standard SQL, you could just store the columns in other tables,
referenced by foreign keys. On the Sequel side, you would just use an
association. You can still create accessor methods for each column so that
the API doesn't
change much:
def column_in_associated_table
association.column
end
Because associations are cached, the performance impact is minimal, and may
even perform better depending on the use case.
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.