Hello Guys, does anybody know wheter RoR is able to implement a generalisation of a database? I didn''t find any solution for that on the internet. Example Person : Customer or Person : Employee in the database such a generalisation is characterized by having the same PK in Customer and Person or Employee and Person! -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 22 May 2011 09:37, Wolfgang <wolfgang.grim-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello Guys, > > does anybody know wheter RoR is able to implement a generalisation of > a database? I didn''t find any solution for that on the internet. > > Example > > Person : Customer > > > or > > Person : Employee > > in the database such a generalisation is characterized by having the > same PK in Customer and Person or Employee and Person!Would Single Table Inheritance (STI) do what you want? Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
STI is a good approach, but my "subtables" have additional attributes and afaik this isn''t supportet by STI, is it? For example: user << Base id firstname lastname address end employee << user <all of the above and additionally:> salary end On 22 Mai, 10:41, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 22 May 2011 09:37, Wolfgang <wolfgang.g...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > > > Hello Guys, > > > does anybody know wheter RoR is able to implement a generalisation of > > a database? I didn''t find any solution for that on the internet. > > > Example > > > Person : Customer > > > or > > > Person : Employee > > > in the database such a generalisation is characterized by having the > > same PK in Customer and Person or Employee and Person! > > Would Single Table Inheritance (STI) dowhat you want? > > Colin-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 22 May 2011 11:35, Wolfgang <wolfgang.grim-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> STI is a good approach, but my "subtables" have additional attributes > and afaik this isn''t supportet by STI, is it?Yes, you just put the whole set of all attributes in the table. It wastes a small amount of space in the db but generally that is not an issue. Colin> > For example: > > user << Base > id > firstname > lastname > address > end > > employee << user > <all of the above and additionally:> > salary > end > > On 22 Mai, 10:41, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> On 22 May 2011 09:37, Wolfgang <wolfgang.g...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> >> >> >> >> >> >> >> > Hello Guys, >> >> > does anybody know wheter RoR is able to implement a generalisation of >> > a database? I didn''t find any solution for that on the internet. >> >> > Example >> >> > Person : Customer >> >> > or >> >> > Person : Employee >> >> > in the database such a generalisation is characterized by having the >> > same PK in Customer and Person or Employee and Person! >> >> Would Single Table Inheritance (STI) dowhat you want? >> >> Colin > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Wolfgang wrote in post #1000187:> STI is a good approach, but my "subtables" have additional attributes > and afaik this isn''t supportet by STI, is it? > > For example: > > user << Base > id > firstname > lastname > address > end > > employee << user > <all of the above and additionally:> > salary > endIn the past I used a framework that supported other techniques besides Single-Table Inheritance. There were actually two other options that were called Horizontal and Vertical Inheritance. Of those options Vertical Inheritance was the closest to what we think of as object inheritance (as you described above), but was also the least efficient. The issue is that both Horizontal and Vertical inheritance require multiple queries to get to all the data you need, which causes performance problems. Even with a framework that supported the other techniques, using STI was strongly recommended. The performance costs of either Horizontal or Vertical was simply too high. Inheritance doesn''t map well to RDBMS. The cost of the null fields in a single table that contains all attributes for the entire inheritance hierarchy is negligible compared to the other techniques. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Honestly, I''ve always preferred single-table inheritance. I am new to Rails, but in Java, this is what I''ve always done and it just works really nicely and it''s more performant than forcing multiple joins whenever you want to query users - which is probably going to be often. I am finding other problems that are Rails-specific with subclasses... like when submitting forms with simple_for, the parameters hash isn''t the base class by default, so I am having trouble forcing it to be the base-class... but structurally, single-table inheritance is a sound practice. Been doing it for over a decade. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thank you very much for your answers, I''ve decided to use STI On 23 Mai, 16:28, egervari <ken.egerv...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Honestly, I''ve always preferred single-table inheritance. I am new to > Rails, but in Java, this is what I''ve always done and it just works > really nicely and it''s more performant than forcing multiple joins > whenever you want to query users - which is probably going to be > often. > > I am finding other problems that are Rails-specific with subclasses... > like when submitting forms with simple_for, the parameters hash isn''t > the base class by default, so I am having trouble forcing it to be the > base-class... but structurally, single-table inheritance is a sound > practice. Been doing it for over a decade.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.