On 10 Sep 2009, at 16:08, Jos Elkink wrote:

> This can become quite a long list. Since they are single table  
> inheritance, all the information ends up in one SQL table. I.e.  
> notes have titles and contents, which means that now every item  
> (incl. e.g. knives) have a "title" and "content" field. Not in the  
> class definition, of course, but in the SQL table.
>
> My simple question is: is this bad design? Does this lead to super  
> inefficient database usage? Or is this just fine and common?
>
> In terms of practical usage and coding, the inheritance definitely  
> brings substantial benefits.


Hi Jos

Personally, I follow Date on this, and try to avoid NULLs at every  
step.  Occasionally they are necessary, I can think of one nullable  
column in my current project, although there may be others I forgot  
about.  Having excessively wide tables may or may not be a performance  
issue, depending on the DBMS you're using.  A bigger issue I've found  
is enforcing integrity, eg making sure Knife objects don't end up with  
a note title.

I've been forced to use STI to solve a problem on this current  
project.  To avoid making non-sensical database tables, you can keep  
only the core properties on the STI table, and use associations to  
reference the extra properties.  eg you might have

   class Note < Item
     has 1, :note_description
   end

   class Knife < Item
     has 1, :knife_blade
   end

etc.  Although watch out, there are still a couple[1][2] of issues  
with STI.  That said, it can make some problems much easier to solve.   
But treat large class hierarchies as a warning sign - if you have too  
much inheritance, you may be coupling some of your code too tightly.   
(Again, my personal preference is to never use inheritance, but  
occasionally it is the most pragmatic solution.)

HTH
Ashley


[1] 
http://datamapper.lighthouseapp.com/projects/20609/tickets/1001-sti-broken-when-subclassed-parent-to-a-child-possibly-connected-in-some-way-to-validation-code
[2] 
http://datamapper.lighthouseapp.com/projects/20609/tickets/1002-sti-association-not-accessible-on-certain-reloaded-resources



-- 
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
http://aviewfromafar.net/








--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to