Howdy, I have a couple questions on the best way to model things in rails. 1. How to model a table so an admin person can selectively turn on/ off hard/soft deletes from a table at a table level? 2. Model a parent/child relationship that can go infinitely deep. specifically equipment, parent => child => child => child .... -- 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 Thu, Nov 18, 2010 at 9:50 PM, Me <chabgood-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Howdy, I have a couple questions on the best way to model things in > rails. > > 1. How to model a table so an admin person can selectively turn on/ >Use acts as paranoid plugin.> off hard/soft deletes from a table at a table level? > 2. Model a parent/child relationship that can go infinitely deep. > specifically equipment, parent => child => child => child .... > > Use acts as tree plugin> -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Cheers, Bala RoR Developer Now Available for Hire -- 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.
Bala Paranj wrote in post #962528: [...]>> 2. Model a parent/child relationship that can go infinitely deep. >> specifically equipment, parent => child => child => child .... >> >> Use acts as tree pluginHell no! acts_as_tree should be avoided at all costs. The adjacency list model that it uses is simple, naïve, and inefficient: each level of the tree requires a separate query (unless you''re using Oracle, which has a proprietary extension to its SQL that fixes this). What you want instead is a *nested set* or *nested interval* structure (do a Web search for articles on how these work). These allow retrieval of an entire tree, to arbitrary depth, with a single query. Rails plugins exist for both. acts_as_nested_interval was buggy last time I used it, but has probably been fixed by now. awesome_nested_set lives up to its name.> >> > -- > Cheers, > Bala > RoR Developer Now Available for HireThe fact that you''re recommending acts_as_tree means that people ought to think twice about hiring you... Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Hello, 2. http://guides.rubyonrails.org/association_basics.html Here check has_many :through , has_and_belongs_to_many assotiations, and I think you may need polymorphic association. You have to try them out, but there are some help in the tutorial to make decision. I''m not sure if I understand well your first question, can you write it more clearly please? good luck, gezope On nov. 19, 05:50, Me <chabg...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Howdy, I have a couple questions on the best way to model things in > rails. > > 1. How to model a table so an admin person can selectively turn on/ > off hard/soft deletes from a table at a table level? > 2. Model a parent/child relationship that can go infinitely deep. > specifically equipment, parent => child => child => child ....-- 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.
Please quote when replying. Zoltan Gero wrote in post #962586:> Hello, > > 2. http://guides.rubyonrails.org/association_basics.html > Here check has_many :through , has_and_belongs_to_many assotiations, > and I think you may need polymorphic association. You have to try them > out, but there are some help in the tutorial to make decision.Nope. All you need is awesome_nested_set.> > I''m not sure if I understand well your first question, can you write > it more clearly please? > > good luck, > gezopeBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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.
On Nov 19, 12:23 pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > Hell no! acts_as_tree should be avoided at all costs. The adjacency > list model that it uses is simple, naïve, and inefficient: each level of > the tree requires a separate query (unless you''re using Oracle, which > has a proprietary extension to its SQL that fixes this). > > What you want instead is a *nested set* or *nested interval* structure > (do a Web search for articles on how these work). These allow retrieval > of an entire tree, to arbitrary depth, with a single query. Rails > plugins exist for both. acts_as_nested_interval was buggy last time I > used it, but has probably been fixed by now. awesome_nested_set lives > up to its name. >Although nested sets make inserts very expensive. Like most data modelling questions, the sort of access patterns that will be used - while acts as tree makes getting a whole subtree expensive, if you never need to do that in your app, who cares? Fred> > > > -- > > Cheers, > > Bala > > RoR Developer Now Available for Hire > > The fact that you''re recommending acts_as_tree means that people ought > to think twice about hiring you... > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > > Sent from my iPhone > > -- > Posted viahttp://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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote in post #962721:> On Nov 19, 12:23pm, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> used it, but has probably been fixed by now. awesome_nested_set lives >> up to its name. >> > > Although nested sets make inserts very expensive.So use nested intervals instead. They fix that problem completely.> Like most data > modelling questions, the sort of access patterns that will be used - > while acts as tree makes getting a whole subtree expensive, if you > never need to do that in your app, who cares?If you never need a whole subtree, you probably don''t need a tree structure in the first place (though there are exceptions).> > FredBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.