On Dec 28, 8:07 pm, Mark Reginald James <m...@bigpond.net.au> wrote:
> One alternative is to make the ancestor array a string key > to each record ("abe|homer|bart"), allowing instant retrieval. This seems like a relatively good idea, could have a string-key called family_tree or something and just do find_by_family_tree("abe|homer| bart") This doesn't quite feel right - it seems like the only info you should need to keep is a person's parent (from which you can then find their parent and so forth). It might also lead to some very long strings eventually! > > Another would be to build the sql iteratively: > This is what I'm doing at the moment - I'm using the "betternestedset" plugin, so have access to a "children" method that returns an arrary of children. Will this have all been pre-fetched efficiently? And if so, is the iterative code the way to do it? tree = ["abe","homer","bart"] person = Person.find_by_name(tree[0]) if tree.size > 1 1.upto(tree.size - 1) do |i| person = person.children.find { |child| child.name == tree [i] } end end @person = person Thanks for the help, DAZ --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---